moduledb
Database access module
Basic module. Can be used to create and operate database resources, reference method:
1
2var db = require('db');
var conn = db.open('rng://user:pass@host:port/dbname');
By specifying the database engine, different database links can be established. fibjs has two built-in SQL engines: sqlite and mysql. It also supports connecting to more databases through ODBC/unixODBC. Based on ODBC/unixODBC, fibjs has built drivers for mssql and PostgreSQL. In order to use ODBC/unixODBC, you need to install the corresponding driver. To use mssql under posix, you need to install freetds. To use PostgreSQL, you need to install psqlodbc. Under normal circumstances, the driver can be used directly after successful installation without further configuration.
static function
open
Open a database. This method is a universal entry. Different engines are called according to the provided connString.
1static object db.open(String connString) async;
Call parameters:
- connString: String, database description, such as: mysql://user:pass@host/db
Return results:
- object, returns the database connection object
openMySQL
Open a mysql database
1static MySQL db.openMySQL(String connString) async;
Call parameters:
- connString: String, database description, such as: mysql://user:pass@host/db
Return results:
- MySQL, returns the database connection object
openSQLite
Open a sqlite database
1static SQLite db.openSQLite(String connString) async;
Call parameters:
- connString: String, database description, such as: sqlite:test.db or test.db
Return results:
- SQLite, returns the database connection object
openOdbc
Open a sqlite database
1static DbConnection db.openOdbc(String connString) async;
Call parameters:
- connString: String, database description, such as: odbc://user:pass@host/db?driver=PostgreSQL%20ANSI
Return results:
- DbConnection, returns the database connection object
openMSSQL
Open a mssql database
1static DbConnection db.openMSSQL(String connString) async;
Call parameters:
- connString: String, database description, such as: mssql://user:pass@host/db
Return results:
- DbConnection, returns the database connection object
In order to establish a connection with mssql, the odbc driver of freetds must be installed under POSIX. You can also use Microsoft's mssql driver by specifying the driver. The way to specify the driver is inurlThen add the option ?driver=msodbcsql17[.so/.dylib].
openPSQL
Open a PostgresSQL database
1static DbConnection db.openPSQL(String connString) async;
Call parameters:
- connString: String, database description, such as: psql://user:pass@host/db
Return results:
- DbConnection, returns the database connection object
In order to establish a connection with PostgresSQL, the PostgresSQL odbc driver must be installed.
openLevelDB
Open a leveldb database
1static LevelDB db.openLevelDB(String connString) async;
Call parameters:
- connString: String, database description, such as: level:test.db or test.db
Return results:
- LevelDB, returns the database object
openRedis
open aRedisdatabase
1static Redis db.openRedis(String connString) async;
Call parameters:
- connString: String, database description, such as: redis://server:port or "server"
Return results:
- Redis, returns the database connection object