Object built-in object

Object SQLite

SQLite database connection object

use db.open or db.openSQLite Create, create method:

1
var slite = db.openSQLite("sqlite:/path/to/db");

Inheritance

#lineWidth: 1.5 #font: Helvetica,sans-Serif #fontSize: 10 #leading: 1.6 #.this: fill=lightgray #.class: fill=white [<class>object|toString();toJSON()] [<class>DbConnection|type|close();use();begin();commit();rollback();trans();execute();createTable();dropTable();createIndex();dropIndex();insert();find();count();update();remove();format()] [<this>SQLite|fileName;timeout|backup()] [object] <:- [DbConnection] [DbConnection] <:- [SQLite] DbConnection type close() use() begin() commit() rollback() trans() execute() createTable() dropTable() createIndex() dropIndex() insert() find() count() update() remove() format() SQLite fileName timeout backup() object toString() toJSON()

Member attributes

fileName

String, current database file name

1
readonly String SQLite.fileName;

timeout

Integer, query and set the database timeout time, in milliseconds

1
Integer SQLite.timeout;

type

String, query the current connection database type

1
readonly String SQLite.type;

Member function

backup

Back up the current database to a new file

1
SQLite.backup(String fileName) async;

Call parameters:

  • fileName: String, specify the backup database file name

close

Close the current database connection

1
SQLite.close() async;

use

Select the default database for the current database connection

1
SQLite.use(String dbName) async;

Call parameters:

  • dbName: String, specify the database name

begin

Start a transaction on the current database connection

1
SQLite.begin(String point = "") async;

Call parameters:

  • point: String, specify the name of the transaction, not specified by default

commit

Commit the transaction on the current database connection

1
SQLite.commit(String point = "") async;

Call parameters:

  • point: String, specify the name of the transaction, not specified by default

rollback

Roll back the transaction on the current database connection

1
SQLite.rollback(String point = "") async;

Call parameters:

  • point: String, specify the name of the transaction, not specified by default

trans

Enter a transaction to execute a function, and submit or roll back according to the execution of the function

1
Boolean SQLite.trans(Function func);

Call parameters:

  • func: Function, a function executed in a transactional manner

Return result:

  • Boolean, Returns whether the transaction is committed, true for normal commit, false for rollback, and an error is thrown if there is an error in the transaction

The execution of func has three results:

  • The function returns normally, including the end of the operation and the active return, at which time the transaction will be automatically committed
  • The function returns false, at this time the transaction will be rolled back
  • The function runs incorrectly, the transaction is automatically rolled back

Enter a transaction to execute a function, and submit or roll back according to the execution of the function

1 2
Boolean SQLite.trans(String point, Function func);

Call parameters:

  • point: String, specify the name of the transaction
  • func: Function, a function executed in a transactional manner

Return result:

  • Boolean, Returns whether the transaction is committed, true for normal commit, false for rollback, and an error is thrown if there is an error in the transaction

The execution of func has three results:

  • The function returns normally, including the end of the operation and the active return, at which time the transaction will be automatically committed
  • The function returns false, at this time the transaction will be rolled back
  • The function runs incorrectly, the transaction is automatically rolled back

execute

Execute a sql command and return the execution result

1
NArray SQLite.execute(String sql) async;

Call parameters:

  • sql: String, string

Return result:

  • NArray, Returns an array containing the result records. If the request is UPDATE or INSERT, the returned result will also contain affected and insertId. mssql does not support insertId.

Execute an sql command, and return the execution result, can format the string according to the parameters

1 2
NArray SQLite.execute(String sql, ...args) async;

Call parameters:

  • sql: String, format string, optional parameters are specified with ?. For example:'SELECT FROM TEST WHERE [id]=?'
  • args: ..., optional parameter list

Return result:

  • NArray, Returns an array containing the result records. If the request is UPDATE or INSERT, the returned result will also contain affected and insertId. mssql does not support insertId.

createTable

Create data table

1
SQLite.createTable(Object opts) async;

Call parameters:

  • opts: Object, parameter list

dropTable

Delete data table

1
SQLite.dropTable(Object opts) async;

Call parameters:

  • opts: Object, parameter list

createIndex

Create data table index

1
SQLite.createIndex(Object opts) async;

Call parameters:

  • opts: Object, parameter list

dropIndex

Delete data table index

1
SQLite.dropIndex(Object opts) async;

Call parameters:

  • opts: Object, parameter list

insert

Insert new record

1
Number SQLite.insert(Object opts) async;

Call parameters:

  • opts: Object, parameter list

Return result:

  • Number, Returns the id containing the insert, or 0 if the engine does not support it

find

Query data according to specified conditions

1
NArray SQLite.find(Object opts) async;

Call parameters:

  • opts: Object, parameter list

Return result:

  • NArray, Returns the record containing the result

count

Count the number of data records according to the specified conditions

1
Integer SQLite.count(Object opts) async;

Call parameters:

  • opts: Object, parameter list

Return result:

  • Integer, Returns the number of records containing the result

update

Update data according to specified conditions

1
Integer SQLite.update(Object opts) async;

Call parameters:

  • opts: Object, parameter list

Return result:

  • Integer, Returns the number of records containing updates

remove

Delete data according to specified conditions

1
Integer SQLite.remove(Object opts) async;

Call parameters:

  • opts: Object, optional parameter list

Return result:

  • Integer, Returns the number of records containing updates

format

Format a sql command and return the formatted result

1 2
String SQLite.format(String method, Object opts);

Call parameters:

  • method: String, specify the requested method
  • opts: Object, optional parameter list

Return result:

  • String, Returns the formatted sql command

Format a sql command and return the formatted result

1 2
String SQLite.format(String sql, ...args);

Call parameters:

  • sql: String, format string, optional parameters are specified with ?. For example:'SELECT FROM TEST WHERE [id]=?'
  • args: ..., optional parameter list

Return result:

  • String, Returns the formatted sql command

toString

Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics

1
String SQLite.toString();

Return result:

  • String, Returns the string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object

1
Value SQLite.toJSON(String key = "");

Call parameters:

  • key: String, unused

Return result:

  • Value, Returns a value containing JSON serializable