g’day
After quite some discussion with @refset (thanks for the attitude, man), i managed to make some initial cut of python http client over transit+json, and a separate query-builder for xtql (well, as of docs - and sources - so far). Beware - this is edgy
- dbclient is http-stuff (needs transit-python2, and stuff from …/base)
- qs.py is the xtql query builder (completely independent of all else)
- try2.py is some probes of this and that
i have changed the names of some things here-there from xtql-specs, as of my likings of ergonomics and readability/understandability. But yes, it’s quite of a mess / flux YMMV
btw: xtql is very composable , may be needs some tuning as of names and syntax sugar and some details and similar stuff, but feels great anyway.
e.g. example.py:
from xtdb2.dbclient import xtdb2, Keyword, Symbol
import sys
db = xtdb2( [*sys.argv[1:2], 'http://localhost:3000' ][0] )
docs = [
dict( a=1, b=2, **{ db.id_name: 15}) ,
dict( a=2, b=3, **{ db.id_name: 16}) ,
dict( a=2, b=4, **{ db.id_name: 18}) ,
]
txkey = db.tx( docs, table= 'atable' )
from xtdb2 import qs
qs.sym, qs.kw, qs.sym_wild = Symbol, Keyword, Symbol( '*')
from xtdb2.qs import *
print( *db.query( s(
pipeline(
fromtable( 'atable', ), #all of it
where( funcs.eq( Var('a'), 2 )),
with_columns( z= funcs.add( Var('b'), 1) ),
orderby( orders={ db.id_name: True } ),
limit( 3),
)),
after_tx= txkey, #eh.. no db.sync yet
), sep='\n')
run it from inside xtdb2/ folder
$ PYTHONPATH=.. python example.py
...lots of debug stuff...
frozendict({'a': 2, 'xt/id': 18, 'b': 4, 'z': 5})
frozendict({'a': 2, 'xt/id': 16, 'b': 3, 'z': 4})
frozendict({'a': 2, 'xt/id': 8, 'b': 4, 'z': 5})
keep up good work, and have fun!
svil