tencent cloud

Database Overview
Last updated:2025-03-11 20:05:05
Database Overview
Last updated: 2025-03-11 20:05:05
Database represents a database instance, which is capable of interacting with the database.

Creation

Database instance creation is performed using new, as shown below:
new (driverName: string, dataSourceName: string): Database

Parameters

Parameter
Type
Description
driverName
string
The driver name, currently supports 'mysql'.
dataSourceName
string
Data source.

Methodology

Methodology
Return Type
Description
Result
Execute queries without returning row data.
Record<string, any>[]
Execute queries and return row results, typically a SELECT.

Samples

Creating a Database instance and interacting with it:
import sql from 'pts/sql';

// Create a database instance using new.
const db = new sql.Database(sql.MySQL, "user:passwd@tcp(ip:port)/database")

export default function () {
let result = db.exec("UPDATE user SET age=? WHERE name='zhangsan'", Math.floor(Math.random() * 100));
console.log(JSON.stringify(result)); // {"lastInsertId":0,"rowsAffected":1}

let rows = db.query("SELECT * FROM user");
console.log(JSON.stringify(rows)); // [{"id":1,"name":"zhangsan","age":23},{"id":2,"name":"lisi","age":2}]
}


Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback