@ladc/mysql-adapter
TypeScript icon, indicating that this package has built-in type declarations

0.22.15 • Public • Published

@ladc/mysql-adapter

Build Status npm Type definitions GitHub

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 mysql.

Install

npm install @ladc/mysql-adapter ladc

Use a MySQL connection with LADC

How to create a connection:

import ladc from "ladc";
import mysqlAdapter from "@ladc/mysql-adapter";

const cn = ladc({
  adapter: mysqlAdapter({
    mysqlConfig: {
      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 mysqlAdapter from "@ladc/mysql-adapter";
import sqlBricksModifier from "@ladc/sql-bricks-modifier";

const cn = ladc({
  adapter: mysqlAdapter({
    mysqlConfig: {
      host: "-my-server-",
      database: "-my-database-",
      user: "-my-user-",
      password: "-my-password-",
    },
  }),
  modifier: sqlBricksModifier({
    toParamsOptions: { placeholder: "?" }, // ← Specific to MySQL
  }),
});

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)

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.22.150latest

Version History

VersionDownloads (Last 7 Days)Published
0.22.150
0.22.140
0.22.130
0.22.120

Package Sidebar

Install

npm i @ladc/mysql-adapter

Weekly Downloads

0

Version

0.22.15

License

CC0-1.0

Unpacked Size

25.9 kB

Total Files

13

Last publish

Collaborators

  • paleo