🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

mysql-with-kysely

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mysql-with-kysely

Use MySQL with kysely

0.2.2
latest
Source
npm
Version published
Maintainers
1
Created
Source

mysql-with-kysely

CI codecov npm version license npm downloads

  • mysql-with-kysely use mysql2 and kysely
  • Handle MySQL BIGINT type as string
  • Incorrect arguments to mysqld_stmt_execute error safe!

Installation

$ yarn add mysql-with-kysely

Usages

import { toInsertableSchema, toFullSelectableSchema, WithSchema, connect, queryBuilder } from 'mysql-with-kysely'
import type { User } from './model'

// for query builder
type Database = {
  user: WithSchema<User>
}

// for your code
type SelectableSchema = toFullSelectableSchema<Database>
type InsertableSchema = toInsertableSchema<Database>

const { db, close } = connect<Database>({ uri: 'mysql://root:root@localhost:3306/test' });

// collect your metrics
db.subscribe(({ sql, normalizedSql, durationMs, occurredAt, parameters }) => {
})

// your query builder
const qb = queryBuilder<Database>()

// write your codes type safely
// 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
  .selectFrom('user')
  .selectAll()
  .orderBy('id', 'desc')
  .limit(1),
)

// type of value is `InsertableSchema['user']`
const value = { name: 'kanziw', email: 'kanziwoong@gmail.com' }     
const { insertId } = await db.execute(qb
  .insertInto('user')
  .values(value),
)

// close MySQL connection
await close()

Database type

  • WithPkId: for auto increment id column
  • WithDataLifecycleTracker
    • created_at: for DATETIME DEFAULT CURRENT_TIMESTAMP
    • updated_at: for DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
  • WithSchema: WithPkId & WithDataLifecycleTracker

Keywords

mysql

FAQs

Package last updated on 02 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts