Skip to content

Commit

Permalink
Type SQL dialect
Browse files Browse the repository at this point in the history
  • Loading branch information
frodrigo committed Apr 14, 2024
1 parent 2faeae9 commit dba8383
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
33 changes: 32 additions & 1 deletion lib/overpass_parser/sql_dialect/duckdb.rb
Original file line number Diff line number Diff line change
@@ -1,47 +1,78 @@
# frozen_string_literal: true
# typed: true
# typed: strict

require 'sorbet-runtime'
require 'sorbet-struct-comparable'
require_relative 'sql_dialect'

module OverpassParser
module SqlDialect
extend T::Sig

class Duckdb < SqlDialect
extend T::Sig

sig do
params(key: String).returns(String)
end
def hash_exits(key)
key = escape_literal(key)
"(tags->>#{key}) IS NOT NULL"
end

sig do
params(key: String).returns(String)
end
def hash_get(key)
key = escape_literal(key)
"(tags->>#{key})"
end

sig do
params(_timeout: Integer).returns(String)
end
def statement_timeout(_timeout)
''
end

sig do
returns(String)
end
def json_strip_nulls
''
end

sig do
returns(String)
end
def json_build_object
'json_object'
end

sig do
returns(String)
end
def jsonb_agg
'json_group_array'
end

sig do
returns(String)
end
def st_union
'' # 'ST_Union_Agg'
end

sig do
returns(T.nilable(String))
end
def st_dump_points
nil
end

sig do
returns(String)
end
def st_intersects_extent
'ST_Intersects_Extent'
end
Expand Down
34 changes: 33 additions & 1 deletion lib/overpass_parser/sql_dialect/postgres.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# frozen_string_literal: true
# typed: true
# typed: strict

require 'sorbet-runtime'
require 'sorbet-struct-comparable'
require_relative 'sql_dialect'

module OverpassParser
module SqlDialect
extend T::Sig

class Postgres < SqlDialect
extend T::Sig

Expand All @@ -20,44 +22,74 @@ def initialize(postgres_escape_literal: nil)
@postgres_escape_literal = postgres_escape_literal
end

sig do
params(string: String).returns(String)
end
def escape_literal(string)
@postgres_escape_literal ? @postgres_escape_literal.call(string) : super(string)
end

sig do
params(key: String).returns(String)
end
def hash_exits(key)
key = escape_literal(key)
"tags?#{key}"
end

sig do
params(key: String).returns(String)
end
def hash_get(key)
key = escape_literal(key)
"tags->>#{key}"
end

sig do
params(timeout: Integer).returns(String)
end
def statement_timeout(timeout)
"SET statement_timeout = #{timeout};"
end

sig do
returns(String)
end
def json_strip_nulls
'jsonb_strip_nulls'
end

sig do
returns(String)
end
def json_build_object
'jsonb_build_object'
end

sig do
returns(String)
end
def jsonb_agg
'jsonb_agg'
end

sig do
returns(String)
end
def st_union
'ST_Union'
end

sig do
returns(T.nilable(String))
end
def st_dump_points
'ST_DumpPoints'
end

sig do
returns(String)
end
def st_intersects_extent
'ST_Intersects'
end
Expand Down
4 changes: 3 additions & 1 deletion lib/overpass_parser/sql_dialect/sql_dialect.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true
# typed: true
# typed: strict

require 'sorbet-runtime'
require 'sorbet-struct-comparable'

module OverpassParser
module SqlDialect
extend T::Sig

class SqlDialect
extend T::Sig

Expand Down

0 comments on commit dba8383

Please sign in to comment.