{"id":13673246,"url":"https://github.com/denodrivers/mysql","last_synced_at":"2025-04-05T02:09:55.169Z","repository":{"id":41863457,"uuid":"172351720","full_name":"denodrivers/mysql","owner":"denodrivers","description":" MySQL driver for Deno","archived":false,"fork":false,"pushed_at":"2024-06-26T15:25:44.000Z","size":235,"stargazers_count":261,"open_issues_count":22,"forks_count":65,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-28T08:06:34.307Z","etag":null,"topics":["database","deno","deno-mysql","mariadb"],"latest_commit_sha":null,"homepage":"https://deno-mysql.netlify.com/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/denodrivers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["manyuanrong"],"ko_fi":"manyuanrong"}},"created_at":"2019-02-24T15:03:25.000Z","updated_at":"2025-03-25T20:58:42.000Z","dependencies_parsed_at":"2024-01-05T21:00:13.825Z","dependency_job_id":"9bb92a4f-1e57-4199-a6e5-c33db1dc191e","html_url":"https://github.com/denodrivers/mysql","commit_stats":{"total_commits":190,"total_committers":32,"mean_commits":5.9375,"dds":0.5736842105263158,"last_synced_commit":"e9da7ca5b5636fc45c99055723ec35612e231ab6"},"previous_names":["manyuanrong/deno_mysql"],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denodrivers%2Fmysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denodrivers%2Fmysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denodrivers%2Fmysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denodrivers%2Fmysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denodrivers","download_url":"https://codeload.github.com/denodrivers/mysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245991581,"owners_count":20706127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","deno","deno-mysql","mariadb"],"created_at":"2024-08-02T10:00:31.862Z","updated_at":"2025-03-29T01:11:34.970Z","avatar_url":"https://github.com/denodrivers.png","language":"TypeScript","readme":"# deno_mysql\n\n[![Build Status](https://github.com/manyuanrong/deno_mysql/workflows/ci/badge.svg?branch=master)](https://github.com/manyuanrong/deno_mysql/actions)\n![GitHub](https://img.shields.io/github/license/manyuanrong/deno_mysql.svg)\n![GitHub release](https://img.shields.io/github/release/manyuanrong/deno_mysql.svg)\n![(Deno)](https://img.shields.io/badge/deno-1.0.0-green.svg)\n\nMySQL and MariaDB database driver for Deno.\n\nOn this basis, there is also an ORM library:\n[Deno Simple Orm](https://github.com/manyuanrong/dso)\n\n欢迎国内的小伙伴加我专门建的 Deno QQ 交流群：698469316\n\n## API\n\n### connect\n\n```ts\nimport { Client } from \"https://deno.land/x/mysql/mod.ts\";\nconst client = await new Client().connect({\n  hostname: \"127.0.0.1\",\n  username: \"root\",\n  db: \"dbname\",\n  password: \"password\",\n});\n```\n\n### connect pool\n\nCreate client with connection pool.\n\npool size is auto increment from 0 to `poolSize`\n\n```ts\nimport { Client } from \"https://deno.land/x/mysql/mod.ts\";\nconst client = await new Client().connect({\n  hostname: \"127.0.0.1\",\n  username: \"root\",\n  db: \"dbname\",\n  poolSize: 3, // connection limit\n  password: \"password\",\n});\n```\n\n### create database\n\n```ts\nawait client.execute(`CREATE DATABASE IF NOT EXISTS enok`);\nawait client.execute(`USE enok`);\n```\n\n### create table\n\n```ts\nawait client.execute(`DROP TABLE IF EXISTS users`);\nawait client.execute(`\n    CREATE TABLE users (\n        id int(11) NOT NULL AUTO_INCREMENT,\n        name varchar(100) NOT NULL,\n        created_at timestamp not null default current_timestamp,\n        PRIMARY KEY (id)\n    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n`);\n```\n\n### insert\n\n```ts\nlet result = await client.execute(`INSERT INTO users(name) values(?)`, [\n  \"manyuanrong\",\n]);\nconsole.log(result);\n// { affectedRows: 1, lastInsertId: 1 }\n```\n\n### update\n\n```ts\nlet result = await client.execute(`update users set ?? = ?`, [\"name\", \"MYR\"]);\nconsole.log(result);\n// { affectedRows: 1, lastInsertId: 0 }\n```\n\n### delete\n\n```ts\nlet result = await client.execute(`delete from users where ?? = ?`, [\"id\", 1]);\nconsole.log(result);\n// { affectedRows: 1, lastInsertId: 0 }\n```\n\n### query\n\n```ts\nconst username = \"manyuanrong\";\nconst users = await client.query(`select * from users`);\nconst queryWithParams = await client.query(\n  \"select ??,name from ?? where id = ?\",\n  [\"id\", \"users\", 1],\n);\nconsole.log(users, queryWithParams);\n```\n\n### execute\n\nThere are two ways to execute an SQL statement.\n\nFirst and default one will return you an `rows` key containing an array of rows:\n\n```ts\nconst { rows: users } = await client.execute(`select * from users`);\nconsole.log(users);\n```\n\nThe second one will return you an `iterator` key containing an\n`[Symbol.asyncIterator]` property:\n\n```ts\nawait client.useConnection(async (conn) =\u003e {\n  // note the third parameter of execute() method.\n  const { iterator: users } = await conn.execute(\n    `select * from users`,\n    /* params: */ [],\n    /* iterator: */ true,\n  );\n  for await (const user of users) {\n    console.log(user);\n  }\n});\n```\n\nThe second method is recommended only for SELECT queries that might contain many\nresults (e.g. 100k rows).\n\n### transaction\n\n```ts\nconst users = await client.transaction(async (conn) =\u003e {\n  await conn.execute(`insert into users(name) values(?)`, [\"test\"]);\n  return await conn.query(`select ?? from ??`, [\"name\", \"users\"]);\n});\nconsole.log(users.length);\n```\n\n### TLS\n\nTLS configuration:\n\n- caCerts([]string): A list of root certificates (must be PEM format) that will\n  be used in addition to the default root certificates to verify the peer's\n  certificate.\n- mode(string): The TLS mode to use. Valid values are \"disabled\",\n  \"verify_identity\". Defaults to \"disabled\".\n\nYou usually need not specify the caCert, unless the certificate is not included\nin the default root certificates.\n\n```ts\nimport { Client, TLSConfig, TLSMode } from \"https://deno.land/x/mysql/mod.ts\";\nconst tlsConfig: TLSConfig = {\n  mode: TLSMode.VERIFY_IDENTITY,\n  caCerts: [\n    await Deno.readTextFile(\"capath\"),\n  ],\n};\nconst client = await new Client().connect({\n  hostname: \"127.0.0.1\",\n  username: \"root\",\n  db: \"dbname\",\n  password: \"password\",\n  tls: tlsConfig,\n});\n```\n\n### close\n\n```ts\nawait client.close();\n```\n\n## Logging\n\nThe driver logs to the console by default.\n\nTo disable logging:\n\n```ts\nimport { configLogger } from \"https://deno.land/x/mysql/mod.ts\";\nawait configLogger({ enable: false });\n```\n\n## Test\n\nThe tests require a database to run against.\n\n```bash\ndocker container run --rm -d -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=true docker.io/mariadb:latest\ndeno test --allow-env --allow-net=127.0.0.1:3306 ./test.ts\n```\n\nUse different docker images to test against different versions of MySQL and\nMariaDB. Please see [ci.yml](./.github/workflows/ci.yml) for examples.\n","funding_links":["https://github.com/sponsors/manyuanrong","https://ko-fi.com/manyuanrong"],"categories":["Uncategorized","Modules","核心模块与框架（按需求挑）"],"sub_categories":["Uncategorized","Database","数据库工具（操作数据用）"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenodrivers%2Fmysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenodrivers%2Fmysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenodrivers%2Fmysql/lists"}