Connection
The connection in OpenSql is written in the simplest way,
import { OpenSql } from 'opensql';
let opensql = new OpenSql('driver://domain:port/databaseName?user=username&password=password');
Example Code :
import { OpenSql } from 'opensql';
let opensql = new OpenSql('mysql://localhost:3306/foo?user=root&password=123');
When you get an example of open sql, in the constructor part, it receives a parameter of string type, which is the basic information needed to connect to the desired database, then it receives another parameter of object type, which is used in the event of the second argument. If you want to manage your database.
📒Note :
The second argument can have different values depending on the type of driver, so pay full attention to the options of each driver.
Driver | |
---|---|
0 | Mysql |
1 | Postgres |
2 | Microsoft Sql Server (Mssql) |
Port
Naturally, the default ports of each driver are different from each other. A list of default ports
Driver | Port | |
---|---|---|
0 | Mysql | 3306 |
1 | Mssql | 1433 |
2 | Postgresql | 5432 |
Disconnect
To disconnect in OpenSql, use the disconnect method.
Example code :
opensql.disconnect();