hxwebsql 0.5.0

Haxe lib for using cordova sqlite plugin (or browser websql, if plugin missing) in html-applications.

Released 2017-11-01.

To install, run:

haxelib install hxwebsql 0.5.0

See using Haxelib in Haxelib documentation for more information.

Maintainerodanylyshyn
Websitehttps://github.com/odanylyshyn/hxwebsql
Current version0.5.0
StatisticsInstalled 8 times
LicenseMIT
Tags

README.md

under construction

The project is under development. Some functional has not been implemented yet. In this description, working examples are given (you can check them by opening the file /test/test.html)

Requirements

Haxe 3.0 or higher.

Examples

Open database

Create database, if missing.

var db = new Database("TestDB");

Run any SQL query

Here is an example of creating a table.

var q = new SqlQuery('CREATE TABLE IF NOT EXISTS records (username, score)');
q.handler = function(res:SqlQuery):Void { /* ... */ }
db.exec(q);
// or
db.exec('CREATE TABLE IF NOT EXISTS records (username, score)'); // no handler!

Insert

Second query with returning last insert rowid.

var q1 = new SqlQuery('records', SqlOperator.INSERT);
q1.set('username', 'Bob');
q1.set('score', 123);
db.exec(q1);

var q2 = new SqlQuery('records', SqlOperator.INSERT);
q2.set({username: 'Joe', score: 456});
q2.isReturnId = true;
q2.handler = function(res:SqlQuery):Void {
    trace(res.isSuccess);
    trace(res.rows[0].rowid);
};
db.exec(q2);

Update

var q1 = new SqlQuery('records', SqlOperator.UPDATE);
q1.set('score', 900);
q1.whereEq('username', 'Joe');   // WHERE `username`='Joe'

var q2 = new SqlQuery('records', SqlOperator.UPDATE);
q2.set('score', 800);
q2.whereId(3);                   // WHERE `rowid`=3

db.exec(q1);
db.exec(q2);

Update, where list of variants

var q = new SqlQuery('records', SqlOperator.UPDATE);
q.set('score', 555);
q.whereList('username', ['Bob', 'Joe']);     // WHERE `username`='Bob' OR `username`='Joe'
db.exec(q);

Update, where match LIKE-pattern

var q = new SqlQuery('records', SqlOperator.UPDATE);
q.set('score', 1000);
q.whereMatch('username', '%er');             // WHERE `username` LIKE '%er'
db.exec(q);

Delete

var q = new SqlQuery('records', SqlOperator.DELETE);
q.whereEq('username', 'Joe');
db.exec(q);

Select fields with "where"

var q = new SqlQuery('records', SqlOperator.SELECT);
q.selectFields = ['username', 'score'];
q.whereEq('username', 'Joe');
q.handler = function(res:SqlQuery):Void {
    trace(res.isSuccess);
    trace(res.rows);
};
db.exec(q);

Select all with order and limit

var q = new SqlQuery('records', SqlOperator.SELECT);
q.limit = 5;
q.orderFields = ['score'];
q.order = Order.DESCENDING;
q.handler = function(res:SqlQuery):Void {
    trace(res.isSuccess);
    trace(res.rows);
};
db.exec(q);