@dpapejs/emysql
Version:
🛠️ Based on the basic secondary package of `mysql`, the pursuit of creating a simple and easy to use `mysql-ORM` library.
69 lines (61 loc) • 1.46 kB
Markdown



🛠️ Based on the basic secondary package of `mysql`, the pursuit of creating a simple and easy to use `mysql-ORM` library.
```sh
npm i @dpapejs/emysql@latest -S
```
```ts
import emysql from '@dpapejs/emysql' // Reference library
// Function instantiation
const mysql = new emysql({
password: '[database login password]',
user: '[database login username]',
database: 'database name'
})
// Create table structure
await mysql.table.create([
{
tableName: 'create_table',
columns: [
{
name: 'id',
dataType: 'INT',
primaryKey: true,
autoIncrement: true,
comments: '主键id'
},
{
name: 'name',
dataType: 'VARCHAR',
length: 45,
notNull: true,
comments: '名称'
},
{
name: 'create_at',
dataType: 'DATETIME',
notNull: true,
comments: '创建时间'
}
]
}
])
// Insert data
const now = new Date()
await mysql.change.insert({
t: 'create_table',
params: { name: 'test', create_at: now }
})
// Query data
const list = await mysql.query({
t: 'query_test',
fields: ['name', 'id'],
condition: { id: 1 }
})
console.log(list) // [{id:1,name:"test"}]
```