mysql-with-kysely
Advanced tools
Comparing version
{ | ||
"name": "mysql-with-kysely", | ||
"version": "0.0.0-rc-8", | ||
"version": "0.0.1-rc.0", | ||
"repository": { | ||
@@ -17,8 +17,8 @@ "type": "git", | ||
"clean": "rimraf dist/", | ||
"build": "yarn clean && tsc && rimraf dist/__tests__/", | ||
"build": "yarn clean && tsc", | ||
"db:sync": "mysqldef -uroot -proot test < ddl.sql && sql-ts -c dbconfig.json", | ||
"lint": "eslint src", | ||
"lint": "eslint .", | ||
"test": "jest", | ||
"test:integration": "jest -c jest-integration.config.js", | ||
"publish": "yarn build && yarn npm publish --access public" | ||
"publish": "yarn build && yarn publish-if-not-published" | ||
}, | ||
@@ -44,2 +44,3 @@ "devDependencies": { | ||
"lodash": "^4.17.21", | ||
"publish-if-not-published": "^3.1.2", | ||
"rimraf": "^3.0.2", | ||
@@ -56,2 +57,2 @@ "ts-jest": "^27.1.4", | ||
} | ||
} | ||
} |
# mysql-with-kysely | ||
 [](https://codecov.io/gh/kanziw/mysql-with-kysely) | ||
## Installation | ||
```zsh | ||
$ yarn add mysql-with-kysely | ||
``` | ||
## Usages | ||
```ts | ||
import { queryBuilder, WithSchema, SelectableSchema } from 'mysql-with-kysely' | ||
import type { User } from './model' | ||
// for query builder | ||
type Database = { | ||
user: WithSchema<User> | ||
} | ||
// for your code | ||
type Schema = SelectableSchema<Database> | ||
const qb = queryBuilder<Database>() | ||
const { db, close } = connect<Database>({ uri: 'mysql://root:root@localhost:3306/test' }); | ||
// collect your metrics | ||
db.subscribe(({ sql, normalizedSql, durationMs, occurredAt, parameters }) => { | ||
}) | ||
// write your codes type safely | ||
// type of users is `Array<Schema['user']>` | ||
const users = await db.query(qb | ||
.selectFrom('user') | ||
.selectAll() | ||
.orderBy('id', 'desc') | ||
.limit(1), | ||
) | ||
// close MySQL connection | ||
await close() | ||
``` | ||
## Recommended Usages Personally | ||
1. Write DDL | ||
1. See [ddl.sql](./ddl.sql) | ||
2. Prepare types | ||
1. Apply DDL to MySQL Server using [mysqldef](https://github.com/k0kubun/sqldef) | ||
2. Generate model using [sql-ts](https://github.com/rmp135/sql-ts) | ||
3. See `db:sync` script in [package.json](./package.json) | ||
3. Set up your own query builder | ||
1. See [mysql.ts](./src/__tests__/fixtures/mysql.ts) | ||
4. Write your own code! | ||
1. See [integration.spec.ts](./src/__tests__/integration.spec.ts) | ||
5. Write your test code using [createMockMySqlHelper](./src/test/mockMySql.ts) | ||
1. See [mockMySql.spec.ts](./src/__tests__/mockMySql.spec.ts) | ||
6. Subscribe MySQL Metrics | ||
1. See [subscribe.spec.ts](./src/__tests__/subscribe.spec.ts) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
1028843
4262.83%27
8%20285
4188.58%63
3050%22
4.76%9
Infinity%1
Infinity%