Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

driveline

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

driveline

Driveline client

  • 0.14.1
  • PyPI
  • Socket score

Maintainers
1

Driveline Python SDK

At the core of the Python SDK is the class DrivelineClient.

import asyncio

from driveline import DrivelineClient, run_async

async def main():
    async with DrivelineClient('ws://127.0.0.1:8080') as client:

        # list all streams
        async for stream_name in await client.list_streams('*'):
            print('found stream:', stream_name)

        # list all keys is the document store
        async for key_name in await client.list_keys('*'):
            print('found document with key', key_name)


        # store a document in the document store
        await client.store('key/1', dict(title='Welcome', body='Hello, world!'))

        # load a key from the document store
        future_record = await client.load('key/1')
        record = await future_record
        print('document associated with key/1 is:', record.record, 'id:', record.record_id)

        # remove all records in the document store with keys matching 'key/...'
        await client.removeMatches('key/*')

        # run a live query against a stream. 
        # We want all records that have an odd index
        def query_handler(res):
            print('query returned record:', res.record, 'id:', res.record_id)
        query = await client.continuous_query('SELECT * FROM STREAM my_stream where index % 1 == 1', query_handler)


        # stop the query
        await asyncio.sleep(10)
        await client.cancel(query)

        # quit
        await client.close()

if __name__ == '__main__':
    run_async(main())

DQL Driveline Query Language

Query syntax

Basic syntax

SELECT <selector> FROM STREAM <stream> [WHERE <expression>]
SELECT * FROM STREAM stream_1
SELECT * FROM STREAM stream_1 WHERE key=value
SELECT time AS t,(2+3) AS five FROM STREAM stream_1 WHERE age BETWEEN 21 AND 25 OR name LIKE 'Joe%'

DQL supports standard SQL query syntax, excluding Joins and Aggregates. This means DQL can be used for all forms of data filtering and partitioning of data over live streams.

KV query

SELECT <selector> FROM <string-key-name-expression> [WHERE <expression>]
SELECT * FROM 'users/*' WHERE color='red'

Multi key query is a DQL extension 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/Pythong Glob, 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:{...*}} FROM stream

With 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:{...}}}

Operators

The following table summarizes all language operators in order of precedence

NameDescriptionExampleAdditional details
ORextended 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 constants
BETWEENCompare 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 <> b
LIKEPattern 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=9
true false nullConstantSELECT * 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 symbols

Built-in functions

NameDescriptionExample
ABSAbsolute value float=>floatSELECT ABS(-5) AS num FROM stream {num:5}
CEILRounded up value float=>floatSELECT CEIL(4.5) AS num FROM stream {num:5}
FLOORRounded down value float=>floatSELECT FLOOR(4.5) AS num FROM stream {num:4}
EXPNatural exponent float=>floatSELECT EXP(1) AS num FROM stream {num:2.718281828459045}
LNNatural logarithm float=>floatSELECT LN(2) AS num FROM stream {num:0.6931471805599453}
SQRTSquare root float=>floatSELECT SQRT(9) AS num FROM stream {num:3}
HASHHash function any=>uint64SELECT HASH('abc') AS num FROM stream {num:4952883123889572249}
CHAR_LENGTHLength of string string->int32SELECT CHAR_LENGTH('abc') AS num FROM stream {num:3}
POSITIONIndex of substring in string string,string->int32SELECT POSITION('bc' IN 'abc') AS num FROM stream {num:2}
LOCATEIndex of substring in string string,string->int32SELECT LOCATE('bc', 'abc') AS num FROM stream {num:2}

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc