@the-neon/mysql
v0.0.16
Published
MySQL client for Neon using Sequelize
Downloads
552
Readme
@the-neon/mysql
MySQL client for Neon using Sequelize.
Install
npm install @the-neon/mysqlUsage
Requires environment variables:
DB_HOST=localhost
DB_DATABASE=mydb
DB_USER=root
DB_PASSWORD=secretimport MySqlDb, { QueryTypes } from "@the-neon/mysql";
const db = new MySqlDb();
// Transactions
await db.start();
await db.commit();
await db.rollback();
// CRUD
await db.insert<User>("users", { name: "Alice", email: "[email protected]" });
await db.update<User>("users", { id: 1 }, { name: "Alice Updated" });
await db.delete("users", { id: 1 });
// Fetch
await db.getOne<User>("users", { id: 1 });
await db.getMany<User>("users", { tenantId: "abc" });
await db.execute("SELECT * FROM users WHERE id = :id", { id: 1 });API
Transactions
start()— Begin transactioncommit()— Commit transactionrollback()— Rollback transaction
Query
execute(sql, params?, queryType?, conn?)— Execute raw SQL with named parameters
CRUD
insert(table, columns, conn?)— Insert rowupdate(sqlOrTable, condition, columns, conn?)— Update rowsdelete(sqlOrTable, condition, conn?)— Delete rows
Fetch
getOne(sqlOrTable, params?, conn?)— Fetch single rowgetMany(sqlOrTable, params?, conn?)— Fetch multiple rows
Query Types
import { QueryTypes } from "@the-neon/mysql";
QueryTypes.SELECT
QueryTypes.INSERT
QueryTypes.UPDATE
QueryTypes.DELETE