File tree 1 file changed +43
-0
lines changed
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
12
12
13
13
## Usage
14
14
15
+ ### Command Line Interface
16
+
15
17
Assuming you have a directory structure like this:
16
18
17
19
```
@@ -29,6 +31,47 @@ abstra-json-sql "select * from users"
29
31
30
32
This will return all the users in the ` users.json ` file.
31
33
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
+ ```
32
75
## Supported SQL Syntax
33
76
34
77
- [ ] ` WITH `
You can’t perform that action at this time.
0 commit comments