mysql-with-kysely
Advanced tools
Comparing version
@@ -12,9 +12,9 @@ import { ColumnType, Generated, Insertable, Kysely, Selectable } from 'kysely'; | ||
export declare type WithSchema<Schema> = WithPkId<WithDataLifecycleTracker<Schema>>; | ||
export declare type SelectableSchema<Database> = { | ||
export declare type toSelectableSchema<Database> = { | ||
[key in keyof Database]: Omit<Selectable<Database[key]>, 'created_at' | 'updated_at'>; | ||
}; | ||
export declare type FullSelectableSchema<Database> = { | ||
export declare type toFullSelectableSchema<Database> = { | ||
[key in keyof Database]: Selectable<Database[key]>; | ||
}; | ||
export declare type InsertableSchema<Database> = { | ||
export declare type toInsertableSchema<Database> = { | ||
[key in keyof Database]: Insertable<Database[key]>; | ||
@@ -21,0 +21,0 @@ }; |
{ | ||
"name": "mysql-with-kysely", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Use MySQL with kysely", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -26,3 +26,3 @@ # mysql-with-kysely | ||
```ts | ||
import { InsertableSchema, SelectableSchema, WithSchema, connect, queryBuilder } from 'mysql-with-kysely' | ||
import { toInsertableSchema, toFullSelectableSchema, WithSchema, connect, queryBuilder } from 'mysql-with-kysely' | ||
import type { User } from './model' | ||
@@ -36,4 +36,4 @@ | ||
// for your code | ||
type Schema = SelectableSchema<Database> | ||
type InsertValueSchema = InsertableSchema<Database> | ||
type SelectableSchema = toFullSelectableSchema<Database> | ||
type InsertableSchema = toInsertableSchema<Database> | ||
@@ -50,3 +50,4 @@ const { db, close } = connect<Database>({ uri: 'mysql://root:root@localhost:3306/test' }); | ||
// write your codes type safely | ||
// type of users is `Array<Schema['user']>` | ||
// type of users is `Array<SelectableSchema['user']>` | ||
// if you don't need created_at & updated_at, use toSelectableSchema instead of toFullSelectableSchema | ||
const users = await db.query(qb | ||
@@ -59,3 +60,3 @@ .selectFrom('user') | ||
// type of value is `InsertValueSchema['user']` | ||
// type of value is `InsertableSchema['user']` | ||
const value = { name: 'kanziw', email: 'kanziwoong@gmail.com' } | ||
@@ -62,0 +63,0 @@ const { insertId } = await db.execute(qb |
27948
0.51%94
1.08%