0.22.15 • Published 4 years ago

@ladc/mysql-adapter v0.22.15

Weekly downloads
-
License
CC0-1.0
Repository
github
Last release
4 years ago

@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)
0.22.15

4 years ago

0.22.14

4 years ago

0.22.13

4 years ago

0.22.12

4 years ago