@ladc/mysql2-adapter
LADC is a common API on top of relational database (SQL) connectors. It can connect to Postgresql, MariaDB / MySQL, SQLite. The API is inspired from PDO and JDBC. It’s named LADC for “a Layer Above Database Connectors”.
This package is a plugin for LADC. It is an adapter for MySQL and MariaDB, using the connector mysql2.
Install
npm install @ladc/mysql2-adapter ladc
Use a MySQL connection with LADC
How to create a connection:
import ladc from "ladc";
import mysql2Adapter from "@ladc/mysql2-adapter";
const cn = ladc({
adapter: mysql2Adapter({
mysql2Config: {
host: "-my-server-",
database: "-my-database-",
user: "-my-user-",
password: "-my-password-",
},
}),
});
Use a MySQL connection with LADC and SQL Bricks
Add the dependencies for SQL Bricks:
npm install sql-bricks @ladc/sql-bricks-modifier
In your code, MySQL requires to set a specific placeholder
option in SQL Bricks:
import ladc from "ladc";
import mysql2Adapter from "@ladc/mysql2-adapter";
import sqlBricksModifier from "@ladc/sql-bricks-modifier";
const cn = ladc({
adapter: mysql2Adapter({
mysql2Config: {
host: "-my-server-",
database: "-my-database-",
user: "-my-user-",
password: "-my-password-",
},
}),
modifier: sqlBricksModifier({
toParamsOptions: { placeholder: "?" },
}),
});
Now, use it:
import { select } from "sql-bricks";
async function test(cn) {
const q = select("col1, col2").from("table1");
const rows = await cn.all(q);
console.log(rows);
}
Contribute
With VS Code, our recommanded plugin is:
- TSLint from Microsoft (
ms-vscode.vscode-typescript-tslint-plugin
)