Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
connect
✓ import { connect } from 'mysql-with-kysely'
✗ const connect = require('mysql-with-kysely').connect
ESM-only, no default export
queryBuilder
✓ import { queryBuilder } from 'mysql-with-kysely'
✗ import QueryBuilder from 'mysql-with-kysely'
Named function, not a class
WithSchema
✓ import { WithSchema } from 'mysql-with-kysely'
✗ import { withSchema } from 'mysql-with-kysely'
PascalCase type, not camelCase
toInsertableSchema
✓ import { toInsertableSchema } from 'mysql-with-kysely'
Type helper, use with 'type' keyword in ts
createMockMySqlHelper
✓ import { createMockMySqlHelper } from 'mysql-with-kysely/test'
✗ import { createMockMySqlHelper } from 'mysql-with-kysely'
exported from subpath 'mysql-with-kysely/test'
Connects to MySQL, defines typed schema, runs select and insert queries via Kysely, then closes connection.
import { connect, queryBuilder, WithSchema, toFullSelectableSchema, toInsertableSchema } from 'mysql-with-kysely';
type Database = { user: WithSchema<{ id: number; name: string; email: string }> };
type SelectableUser = toFullSelectableSchema<Database>['user'];
type InsertableUser = toInsertableSchema<Database>['user'];
const { db, close } = connect<Database>({ uri: 'mysql://root:root@localhost:3306/test' });
const qb = queryBuilder<Database>();
async function main() {
const users = await db.query(qb.selectFrom('user').selectAll().orderBy('id', 'desc').limit(1));
console.log(users);
const value: InsertableUser = { name: 'kanziw', email: 'kanziwoong@gmail.com' };
const { insertId } = await db.execute(qb.insertInto('user').values(value));
console.log(insertId);
await close();
}
main().catch(console.error);
Errors
Common errors & fixes
Cannot find module 'mysql-with-kysely'
Package not installed or missing
fixnpm install mysql-with-kysely
Incorrect arguments to mysqld_stmt_execute
MySQL 8.0.22+ bug with prepared statements and big integers
fixUse mysql-with-kysely which includes the OffsetLimitTypeCastingPlugin to fix this
Property 'query' does not exist on type 'Kysely<Database>'
Confusing Kysely's db instance with mysql-with-kysely's db wrapper
fixUse the db returned from connect(), which has query() and execute() methods, not the standard Kysely instance
Type 'string' is not assignable to type 'number'
BIGINT is returned as string; TypeScript expects number
fixUse WithSchema which handles BIGINT as string, or cast with Number()
Audit
Dependencies
kyselyrequiredpeer dependency for query building
mysql2requiredpeer dependency for MySQL connection