Object built-in object

Object MySQL

mysql database connection object

Use db.open or db.openMySQL create, create method:

1
var mysql = db.openMySQL("mysql://user:pass@host/db");

Inheritance

Member attributes

rxBufferSize

Integer, database connection receiving buffer size

1
Integer MySQL.rxBufferSize;

txBufferSize

Integer, database connection sending buffer size

1
Integer MySQL.txBufferSize;

type

String, query the current connection database type

1
readonly String MySQL.type;

Member function

use

Select the default database for the current database connection

1
MySQL.use(String dbName) async;

Call parameters:

  • dbName : String, specify the database name

close

Close the current database connection

1
MySQL.close() async;

begin

Start a transaction on the current database connection

1
MySQL.begin() async;

commit

Commit the transaction on the current database connection

1
MySQL.commit() async;

rollback

Roll back the transaction on the current database connection

1
MySQL.rollback() async;

trans

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

1
Boolean MySQL.trans(Function func);

Call parameters:

  • func : Function, function executed in transaction mode

Return result:

  • Boolean , returns whether the transaction is committed, it returns true for normal commit, false for rollback, and throws an error if the transaction fails

There are three results of func execution:

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

execute

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

1 2
NArray MySQL.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 an UPDATE or INSERT, the returned result will also contain affected and insertId. mssql does not support insertId.

insert

Insert new record

1
Number MySQL.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 MySQL.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 MySQL.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 MySQL.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 MySQL.remove(Object opts) async;

Call parameters:

  • opts : Object, optional parameter list

Return result:

  • Integer , returns the number of records containing updates

format

Format an sql command and return the formatted result

1 2
String MySQL.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 an sql command and return the formatted result

1 2
String MySQL.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 MySQL.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 MySQL.toJSON(String key = "");

Call parameters:

  • key : String, unused

Return result:

  • Value , returns a value containing JSON serializable