Package: driveline
Driveline Python SDKAt the core of the Python SDK is the classDrivelineClient.importasynciofromdrivelineimportDrivelineClient,run_asyncasyncdefmain():asyncwithDrivelineClient('ws://127.0.0.1:8080')asclient:# list all streamsasyncforstream_nameinawaitclient.list_streams('*'):print('found stream:',stream_name)# list all keys is the document storeasyncforkey_nameinawaitclient.list_keys('*'):print('found document with key',key_name)# store a document in the document storeawaitclient.store('key/1',dict(title='Welcome',body='Hello, world!'))# load a key from the document storefuture_record=awaitclient.load('key/1')record=awaitfuture_recordprint('document associated with key/1 is:',record.record,'id:',record.record_id)# remove all records in the document store with keys matching 'key/...'awaitclient.removeMatches('key/*')# run a live query against a stream.# We want all records that have an odd indexdefquery_handler(res):print('query returned record:',res.record,'id:',res.record_id)query=awaitclient.continuous_query('SELECT * FROM STREAM my_stream where index % 1 == 1',query_handler)# stop the queryawaitasyncio.sleep(10)awaitclient.cancel(query)# quitawaitclient.close()if__name__=='__main__':run_async(main())DQL Driveline Query LanguageQuery syntaxBasic syntaxSELECT<selector>FROMSTREAM<stream>[WHERE<expression>]SELECT*FROMSTREAMstream_1SELECT*FROMSTREAMstream_1WHEREkey=valueSELECTtimeASt,(2+3)ASfiveFROMSTREAMstream_1WHEREageBETWEEN21AND25ORnameLIKE'Joe%'DQLsupports standardSQLquery syntax, excluding Joins and
Aggregates. This meansDQLcan be used for all forms of data filtering
and partitioning of data over live streams.KV querySELECT<selector>FROM<string-key-name-expression>[WHERE<expression>]SELECT*FROM'users/*'WHEREcolor='red'Multi key query is aDQLextension that lets you subscribe to multiple
event streams, automatically subscribing to new streams as they form,
based on the stream name expression. Stream name expression use file-system/PythongGlob,
with?,*and**serving as the wildcard match characters.ECMAScript Object Notation (JavaScript extensions)SELECT{time,name:user.name,phone_number:user.phone.mobile.number,original:{...*}}FROMstreamWith inputs of the form:{time:123,user:{name:'joe',phone:{mobile:{number:'1-800-123-4567'}}}}Results in:{time:123,name:'joe',phone_number:'1-800-123-4567',original:{time:123,user:phone:{...}}}OperatorsThe following table summarizes all language operators in order of
precedenceNameDescriptionExampleAdditional detailsORextended logical ORSELECT * FROM STREAM stream WHERE a OR bif (a) return a; else return b;ANDlogical ANDSELECT * FROM STREAM stream WHERE a AND bif (a && b) return true; else return false;NOTlogical NOTSELECT * FROM STREAM stream WHERE NOT aif (a) return false; else return true;IS [NOT] NULLNull checkSELECT * FROM STREAM stream WHERE a IS NOT NULLif (null===a) return true; return false;INSet lookupSELECT * FROM STREAM stream WHERE a IN (1,2,3)All values in paranthesis must be constantsBETWEENCompare rangeSELECT * FROM STREAM stream WHERE a BETWEEN b AND cif (b<c) return (a>=b && a<=c); else return (a>=c && a<=b);=>=<=!=><!<!><>CompareSELECT * FROM STREAM STREAM WHERE a <> bLIKEPattern matchSELECT * FROM STREAM stream WHERE a like '%b%'_stands for single,%stands for multi-char match+-Unary plus/minusSELECT * FROM STREAM stream WHERE -5 < +5+-AdditionSELECT * FROM STREAM stream WHERE 1+2=3*/%MultiplicativeSELECT * FROM STREAM stream WHERE 3%2=1( exp )ParanthesisSELECT * FROM STREAM stream WHERE (1+2)*3=9truefalsenullConstantSELECT * FROM STREAM stream WHERE true != false-123.45e-1Numeric constant'hello'String constantSELECT * FROM stream WHERE name='joe'nameIdentifierSELECT name FROM STREAM stream`user name`IdentifierSELECT `user name` FROM STREAM stream(backticks) Allows using identifier names that are otherwise invalid, e.g., contain invalid characters or symbolsBuilt-in functionsNameDescriptionExampleABSAbsolute valuefloat=>floatSELECT ABS(-5) AS num FROM stream{num:5}CEILRounded up valuefloat=>floatSELECT CEIL(4.5) AS num FROM stream{num:5}FLOORRounded down valuefloat=>floatSELECT FLOOR(4.5) AS num FROM stream{num:4}EXPNatural exponentfloat=>floatSELECT EXP(1) AS num FROM stream{num:2.718281828459045}LNNatural logarithmfloat=>floatSELECT LN(2) AS num FROM stream{num:0.6931471805599453}SQRTSquare rootfloat=>floatSELECT SQRT(9) AS num FROM stream{num:3}HASHHash functionany=>uint64SELECT HASH('abc') AS num FROM stream{num:4952883123889572249}CHAR_LENGTHLength of stringstring->int32SELECT CHAR_LENGTH('abc') AS num FROM stream{num:3}POSITIONIndex of substring in stringstring,string->int32SELECT POSITION('bc' IN 'abc') AS num FROM stream{num:2}LOCATEIndex of substring in stringstring,string->int32SELECT LOCATE('bc', 'abc') AS num FROM stream{num:2}