Client Driver
Given the specific operation of the Database Web Gateway protocol, a Javascript client driver library MUST BE provided along with the server-side server systems. Java and Swift proxies SHOULD BE provided for mobile platforms. A Rustlang the RECOMMENDED platform to build client drivers, with its ability for compiling to WebAssembly+Javascript for web browsers, and language wrappers for Java and Swift.
Features
MUST maintain a web socket connection, including initial establishment and reconnection
MUST provide an async/promise API where communication failures and other errors are thrown for the awaiter to catch.
Simple select example :
var directory = Database.Start({host:"acme.net:91", token: this.token}); var db = directory.resolve(["cars"]); //resolve(readonlyArray, writeableArray). This creates an object with context, and internally it starts resolving. When the first query is executed, that resolution is awaited var result_set = await db.query(`select * from cars.colour_options C where car_id = $0;`, car_id); while (isInScope(result_set) && await result_set.gotNextBatch()) { if (isInScope(result_set.current_batch) == false) //scope might have changed since query continue; optionsUI.apply(result_set); }Simple composite insert example:
var directory = Database.Start({host:"acme.net:91", token: this.token}); var db = directory.resolve(["cars"]); //resolve(readonlyArray, writeableArray). This creates an object with context, and internally it starts resolving. When the first query is executed, that resolution is awaited var batch = db.createFixedQueryBatch(4); await batch.run("insert into orders (...) values (...);"); await batch.run("var @order_id = last_order_id();"); await batch.run("insert into order_item (...) values (@order_id...);"); await batch.query("select last_order_item_id();"); await batch.flush(); var order_item_id = await batch.result.single(); batch = null;Advanced paged select context:
function CarsReadOnlyAdaptor() { var directory = await Database.Start({host:"acme.net:91", token: this.token}); var db = directory.resolve(["cars", "brands"]); //resolve(readonlyArray, writeableArray). This creates an object with context, and internally it starts resolving. When the first query is executed, that resolution is awaited return { db: db, viewPort: { fixed: 10 ... }, dataBuffer: { }, filters: [], sorts: [], fetchMissing: function() { ... var result_set = await db.query(`select * from cars.catalogue C join brands.vendors B on B.ID = C.vendor_id limit 100 offset {requiredOffset};`); while (isInScope(result_set) && await result_set.gotNextBatch()) { if (isInScope(result_set.current_batch) == false) //scope might have changed since query continue; dataBuffer.Store(result_set); } ... }, trimDataBuffer: ... hintViewPort: ..., requireViewPort: ..., }; } Last updated
Was this helpful?