Skip to main content

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
0Mysql
1Postgres
2Microsoft Sql Server (Mssql)

Port

Naturally, the default ports of each driver are different from each other. A list of default ports

DriverPort
0Mysql3306
1Mssql1433
2Postgresql5432

Disconnect

To disconnect in OpenSql, use the disconnect method.

Example code :

opensql.disconnect();