Fork from @nicgene/workers-mysql-client.
The script uses the MySQL driver from Deno and produces a JavaScript (TypeScript) version to be used in workers (eg Cloudflare Workers).
- Updated dependencies.
- Increased documentation.
- Install Deno
- Build
yarn install
yarn build
- Remove top-level await by wrapping with an
async
. Search for "await setup" inmysql.js
.
Broken:
await setup(DEFAULT_CONFIG)
var mod = await (async function () {
return {
LogLevels,
Logger,
LoggerConfig,
handlers,
getLogger,
debug,
info,
warning,
error,
critical,
setup,
}
})()
var logger = mod.getLogger()
Fixed:
let mod
let logger
;(async () => {
try {
await setup(DEFAULT_CONFIG)
} catch (err) {
console.error(err)
}
mod = await (async function () {
return {
LogLevels,
Logger,
LoggerConfig,
handlers,
getLogger,
debug,
info,
warning,
error,
critical,
setup,
}
})()
logger = mod.getLogger()
})()
- Comment out second
case 18
. Search for "case 18" inmysql.js
.
Broken:
case 18:
return new Date(val)
Fixed:
// case 18:
// return new Date(val)
-
Copy
build/mysql.js
to your project. -
Create TypeScript type definition in your project. Incomplete:
export type MySQLClient = {
execute(str: string): Promise<MySQLResponse>
query<T>(str: string, params: unknown[]): Promise<T>
}
export type MySQLResponse = {
affectedRows: number
lastInsertId: number
}
A copy of mysql.js is provided.
Raise an issue if there's a better way :)
This is an experimental module.
Heavily based on bubblydoo/cloudflare-workers-postgres-client .
npm i @nicgene/workers-mysql-client
# or
yarn add @nicgene/workers-mysql-client