File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11module 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+
339end # module
You can’t perform that action at this time.
0 commit comments