Skip to content
MySQL driver for Deno
Branch: master
Clone or download
Latest commit 5e5ef79 Mar 7, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src fix replacePrams error for array Mar 7, 2019
tests fix replacePrams error for array Mar 7, 2019
.gitignore add test cases Feb 27, 2019
.travis.yml
LICENSE
README.MD
deps.ts
mod.ts rename modules.ts to deps.tsexport replaceParams function Mar 7, 2019
test.ts fix replacePrams error for array Mar 7, 2019

README.MD

deno_mysql

Build Status

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

connet

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);
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.