Skip to content

Commit 4d835ff

Browse files
committed
Add initial implementation
1 parent 4611549 commit 4d835ff

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/QuerySQLite.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
11
module QuerySQLite
22

3+
import IteratorInterfaceExtensions, QueryOperators, QueryableBackend,
4+
TableTraits, SQLite
5+
6+
export SQLiteConnection
7+
8+
struct SQLiteConnection
9+
db::SQLite.DB
10+
end
11+
12+
function SQLiteConnection(file::AbstractString)
13+
db = SQLite.DB(file)
14+
return SQLiteConnection(db)
15+
end
16+
17+
struct SQLiteTable
18+
conn::SQLiteConnection
19+
table::String
20+
end
21+
22+
IteratorInterfaceExtensions.isiterable(x::SQLiteTable) = true
23+
TableTraits.isiterabletable(x::SQLiteTable) = true
24+
IteratorInterfaceExtensions.getiterator(x::SQLiteTable) = SQLite.Query(getfield(x.conn, :db), "SELECT * FROM '$(x.table)';")
25+
26+
Base.getindex(conn::SQLiteConnection, name::AbstractString) = SQLiteTable(conn, name)
27+
Base.getproperty(conn::SQLiteConnection, name::Symbol) = SQLiteTable(conn, string(name))
28+
29+
function QueryOperators.query(source::SQLiteTable)
30+
return QueryableBackend.QueryableSource() do querytree
31+
32+
# TODO construct the SQL string here by analyzing querytree
33+
sql_cmd = "SELECT * FROM '$(source.table)';"
34+
35+
return SQLite.Query(getfield(source.conn, :db), sql_cmd)
36+
end
37+
end
38+
339
end # module

0 commit comments

Comments
 (0)