deno_mysql
MySQL database driver for Deno.
Still under development.
On this basis, there is also an ORM library: Deno Simple Orm
欢迎国内的小伙伴加我专门建的Deno QQ交流群:698469316
TODO
- Connecting to database
- Basic login authentication
- Simple queries (no arguments)
- Parsing data types
- Queries with parameters
- Close connection
- Connection pool
- Transaction
- Test case
API
connect
import { Client } from "https://deno.land/x/mysql/mod.ts";
const client = await new Client().connect({
hostname: "127.0.0.1",
username: "root",
db: "dbname",
password: "password"
});
create database
await client.execute(`CREATE DATABASE IF NOT EXISTS enok`);
await client.execute(`USE enok`);
create table
await client.execute(`DROP TABLE IF EXISTS users`);
await client.execute(`
CREATE TABLE users (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(100) NOT NULL,
created_at timestamp not null default current_timestamp,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`);
insert
let result = await client.execute(`INSERT INTO users(name) values(?)`, ["manyuanrong"]);
console.log(result);
// { affectedRows: 1, lastInsertId: 1 }
update
let result = await client.execute(`update users set ?? = ?`, ["name", "MYR"]);
console.log(result);
// { affectedRows: 1, lastInsertId: 0 }
delete
let result = await client.execute(`delete from users where ?? = ?`, ["id", 1]);
console.log(result);
// { affectedRows: 1, lastInsertId: 0 }
query
const username = "manyuanrong";
const users = await client.query(`select * from users where username="${username}"`);
const queryWithParams = await client.query("select ??,name from ?? where id = ?", ["id", "users", 1]);
console.log(users, queryWithParams);