File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ pip install abstra-json-sql
1212
1313## Usage
1414
15+ ### Command Line Interface
16+
1517Assuming you have a directory structure like this:
1618
1719```
@@ -29,6 +31,47 @@ abstra-json-sql "select * from users"
2931
3032This will return all the users in the ` users.json ` file.
3133
34+ ### Python API
35+
36+ You can also use ` abstra-json-sql ` in your Python code. Here's an example:
37+
38+ ``` python
39+ from abstra_json_sql.eval import eval_sql
40+ from abstra_json_sql.tables import InMemoryTables, Table, Column
41+
42+ code = " \n " .join(
43+ [
44+ " select foo, count(*)" ,
45+ " from bar as baz" ,
46+ " where foo is not null" ,
47+ " group by foo" ,
48+ " having foo <> 2" ,
49+ " order by foo" ,
50+ " limit 1 offset 1" ,
51+ ]
52+ )
53+ tables = InMemoryTables(
54+ tables = [
55+ Table(
56+ name = " bar" ,
57+ columns = [Column(name = " foo" , type = " text" )],
58+ data = [
59+ {" foo" : 1 },
60+ {" foo" : 2 },
61+ {" foo" : 3 },
62+ {" foo" : 2 },
63+ {" foo" : None },
64+ {" foo" : 3 },
65+ {" foo" : 1 },
66+ ],
67+ )
68+ ],
69+ )
70+ ctx = {}
71+ result = eval_sql(code = code, tables = tables, ctx = ctx)
72+
73+ print (result) # [{"foo": 3, "count": 2}]
74+ ```
3275## Supported SQL Syntax
3376
3477- [ ] ` WITH `
You can’t perform that action at this time.
0 commit comments