Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FunSQL"
uuid = "cf6cc811-59f4-4a10-b258-a8547a8f6407"
authors = ["Kirill Simonov <xi@resolvent.net>", "Clark C. Evans <cce@clarkevans.com>"]
version = "0.15.0"
authors = ["Kirill Simonov <xi@resolvent.net>", "Clark C. Evans <cce@clarkevans.com>"]

[deps]
DBInterface = "a10d1c49-ce27-4219-8d33-6db1a4562965"
Expand All @@ -11,6 +11,7 @@ LRUCache = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
PrettyPrinting = "54e16d92-306c-5ea0-a30b-337be88ac337"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"

[compat]
DBInterface = "2.5"
Expand All @@ -19,4 +20,5 @@ LRUCache = "1.3"
OrderedCollections = "1.4"
PrettyPrinting = "0.3.2, 0.4"
Tables = "1.6"
URIs = "1.6.1"
julia = "1.10"
2 changes: 2 additions & 0 deletions src/FunSQL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export
funsql_group,
funsql_highlight,
funsql_in,
funsql_into,
funsql_iterate,
funsql_is_not_null,
funsql_is_null,
Expand Down Expand Up @@ -94,6 +95,7 @@ using Tables
using DBInterface
using LRUCache
using DataAPI
using URIs

const SQLLiteralType =
Union{Missing, Bool, Number, AbstractString, Dates.AbstractTime}
Expand Down
23 changes: 14 additions & 9 deletions src/catalogs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@ _metadata_get(dict::SQLMetadata, key::Union{Symbol, AbstractString}, default; st
end

"""
SQLColumn(; name, metadata = nothing)
SQLColumn(name; metadata = nothing)
SQLColumn(; name, private = false, metadata = nothing)
SQLColumn(name; private = false, metadata = nothing)

`SQLColumn` represents a column with the given `name` and optional `metadata`.
If `private` is `true`, the column is excluded from the default query output.
"""
struct SQLColumn
name::Symbol
private::Bool
metadata::SQLMetadata

function SQLColumn(; name::Union{Symbol, AbstractString}, metadata = nothing)
new(Symbol(name), _metadata(metadata))
function SQLColumn(; name::Union{Symbol, AbstractString}, private = false, metadata = nothing)
new(Symbol(name), private, _metadata(metadata))
end
end

SQLColumn(name; metadata = nothing) =
SQLColumn(name = name, metadata = metadata)
SQLColumn(name; private = false, metadata = nothing) =
SQLColumn(; name, private, metadata)

Base.show(io::IO, col::SQLColumn) =
print(io, quoteof(col, limit = true))
Expand All @@ -56,6 +58,9 @@ Base.show(io::IO, ::MIME"text/plain", col::SQLColumn) =

function PrettyPrinting.quoteof(col::SQLColumn; limit::Bool = false)
ex = Expr(:call, nameof(SQLColumn), QuoteNode(col.name))
if col.private
push(ex.args, Expr(:kw, :private, col.private))
end
if !isempty(col.metadata)
push!(ex.args, Expr(:kw, :metadata, limit ? :… : quoteof(reverse!(collect(col.metadata)))))
end
Expand Down Expand Up @@ -122,10 +127,10 @@ struct SQLTable <: AbstractDict{Symbol, SQLColumn}
end

SQLTable(name; qualifiers = Symbol[], columns, metadata = nothing) =
SQLTable(qualifiers = qualifiers, name = name, columns = columns, metadata = metadata)
SQLTable(; qualifiers, name, columns, metadata)

SQLTable(name, columns...; qualifiers = Symbol[], metadata = nothing) =
SQLTable(qualifiers = qualifiers, name = name, columns = [columns...], metadata = metadata)
SQLTable(; qualifiers, name, columns = [columns...], metadata)

_column_map(columns::OrderedDict{Symbol, SQLColumn}) =
columns
Expand Down Expand Up @@ -280,7 +285,7 @@ struct SQLCatalog <: AbstractDict{Symbol, SQLTable}
end

SQLCatalog(tables...; dialect = :default, cache = default_cache_maxsize, metadata = nothing) =
SQLCatalog(tables = tables, dialect = dialect, cache = cache, metadata = metadata)
SQLCatalog(; tables, dialect, cache, metadata)

_table_map(tables::Dict{Symbol, SQLTable}) =
tables
Expand Down
10 changes: 5 additions & 5 deletions src/clauses/internal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

struct WithContextClause <: AbstractSQLClause
dialect::SQLDialect
columns::Union{Vector{SQLColumn}, Nothing}
table::Union{SQLTable, Nothing}

WithContextClause(; dialect, columns = nothing) =
new(dialect, columns)
WithContextClause(; dialect, table = nothing) =
new(dialect, table)
end

const WITH_CONTEXT = SQLSyntaxCtor{WithContextClause}(:WITH_CONTEXT)
Expand All @@ -17,8 +17,8 @@ function PrettyPrinting.quoteof(c::WithContextClause, ctx::QuoteContext)
if c.dialect !== default_dialect
push!(ex.args, Expr(:kw, :dialect, quoteof(c.dialect)))
end
if c.columns !== nothing
push!(ex.args, Expr(:kw, :columns, Expr(:vect, Any[quoteof(col) for col in c.columns]...)))
if c.table !== nothing
push!(ex.args, Expr(:kw, :table, quoteof(c.table)))
end
ex
end
Loading