Neighbor's Preppy Maltese

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

    0.22.14 • Public • Published

    @ladc/mysql2-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 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: "?" }, // ← 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)

    Install

    npm i @ladc/mysql2-adapter

    DownloadsWeekly Downloads

    0

    Version

    0.22.14

    License

    CC0-1.0

    Unpacked Size

    22.3 kB

    Total Files

    12

    Last publish

    Collaborators

    • paleo