Module basic module

Module db

Database access module

Basic module. Can be used to create and manipulate database resources, reference method:

1
var db = require('db');

Static function

open

Open a database, this method is a general entry, call different engines according to the provided connString

1
static object db.open(String connString) async;

Call parameters:

  • connString : String, database description, such as: mysql://user:pass\@host/db

Return result:

  • object , returns the database connection object

openMySQL

Open a mysql database

1
static MySQL db.openMySQL(String connString) async;

Call parameters:

  • connString : String, database description, such as: mysql://user:pass\@host/db

Return result:

  • MySQL , return the database connection object

openMSSQL

Open a mysql database

1
static MSSQL db.openMSSQL(String connString) async;

Call parameters:

  • connString : String, database description, such as: mssql://user:pass\@host/db

Return result:

  • MSSQL , returns the database connection object

openSQLite

Open a sqlite database

1
static SQLite db.openSQLite(String connString) async;

Call parameters:

  • connString : String, database description, such as sqlite:test.db or test.db

Return result:

  • SQLite , returns the database connection object

openMongoDB

Open a mongodb database

1
static MongoDB db.openMongoDB(String connString) async;

Call parameters:

  • connString : String, database description

Return result:

  • MongoDB , returns the database connection object

openLevelDB

Open a leveldb database

1
static LevelDB db.openLevelDB(String connString) async;

Call parameters:

  • connString : String, database description, such as: level: test.db or test.db

Return result:

  • LevelDB , returns database objects

openRedis

Open a Redis database

1
static Redis db.openRedis(String connString) async;

Call parameters:

  • connString : String, database description, such as redis://server:port or "server"

Return result:

  • Redis , return database connection object

format

Format an sql command and return the formatted result

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

Call parameters:

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

Return result:

  • String , returns the formatted sql command

Format an sql command and return the formatted result

1 2
static String db.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

formatMySQL

Format a mysql command and return the formatted result

1 2
static String db.formatMySQL(String method, Object opts);

Call parameters:

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

Return result:

  • String , returns the formatted mysql command

Format a mysql command and return the formatted result

1 2
static String db.formatMySQL(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

formatMSSQL

Format a mssql command and return the formatted result

1 2
static String db.formatMSSQL(String method, Object opts);

Call parameters:

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

Return result:

  • String , returns the formatted mssql command

Format a mssql command and return the formatted result

1 2
static String db.formatMSSQL(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

escape

Encode a string into a SQL-safe encoded string

1 2
static String db.escape(String str, Boolean mysql = false);

Call parameters:

  • str : String, the string to be encoded
  • mysql : Boolean, specify mysql encoding, default is false

Return result:

  • String , returns the encoded string