Skip to content

Commit 43ece86

Browse files
authored
Merge pull request #5 from queryverse/api-tweak
Slightly tweak the API
2 parents f5c863a + 858f848 commit 43ece86

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

src/QuerySQLite.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ sqlite3_column_type, sqlite3_step, sqlitevalue, Stmt, tables
1919
using TableShowUtils: printdataresource, printHTMLtable, printtable
2020
import TableTraits: isiterabletable
2121

22+
export Database
23+
2224
include("utilities.jl")
2325
include("source.jl")
2426
include("iterate.jl")

src/library.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
function get_column(source_row, column_name)
2828
SourceCode(source_row.source, Expr(:call, getproperty, source_row, column_name))
2929
end
30-
function model_row_dispatch(::typeof(getproperty), source_tables::SourceTables, table_name; other = false, options...)
30+
function model_row_dispatch(::typeof(getproperty), source_tables::Database, table_name; other = false, options...)
3131
source = get_source(source_tables)
3232
column_names = get_column_names(source, table_name)
3333
NamedTuple{column_names}(partial_map(
@@ -40,7 +40,7 @@ function model_row_dispatch(::typeof(getproperty), source_tables::SourceTables,
4040
column_names
4141
))
4242
end
43-
function translate_dispatch(::typeof(getproperty), source_tables::SourceTables, table_name; other = false, options...)
43+
function translate_dispatch(::typeof(getproperty), source_tables::Database, table_name; other = false, options...)
4444
if other
4545
translate(table_name)
4646
else

src/source.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@ export get_column_names
2525

2626

2727
"""
28-
struct SourceTables{Source}
28+
struct Database{Source}
2929
3030
`source` must support [`get_table_names`](@ref) and [`get_column_names`](@ref).
3131
"""
32-
struct SourceTables{Source}
32+
struct Database{Source}
3333
source::Source
3434
end
35-
export SourceTables5
3635

37-
get_source(source_tables::SourceTables) = getfield(source_tables, :source)
36+
function Database(filename::AbstractString)
37+
return Database(SQLite.DB(filename))
38+
end
39+
40+
get_source(source_tables::Database) = getfield(source_tables, :source)
3841

39-
function getproperty(source_tables::SourceTables, table_name::Symbol)
42+
function getproperty(source_tables::Database, table_name::Symbol)
4043
SourceCode(get_source(source_tables),
4144
Expr(:call, getproperty, source_tables, table_name)
4245
)

test/runtests.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using Query
22
using Test
3-
using QuerySQLite: SourceTables
4-
using SQLite: DB
3+
using QuerySQLite
4+
import SQLite
55
using QueryTables
66

77
filename = joinpath(@__DIR__, "Chinook_Sqlite.sqlite")
8-
database = SourceTables(DB(filename))
8+
database = Database(filename)
9+
database2 = Database(SQLite.DB(filename))
910

1011
@testset "QuerySQLite" begin
1112

@@ -15,7 +16,7 @@ database = SourceTables(DB(filename))
1516
first |>
1617
propertynames == (:TrackId, :Name, :Composer, :UnitPrice)
1718

18-
@test (database.Customer |>
19+
@test (database2.Customer |>
1920
@map({_.City, _.Country}) |>
2021
@orderby(_.Country) |>
2122
DataTable).Country[1] == "Argentina"

0 commit comments

Comments
 (0)