open-index/open-npm huggingface dataset:
npm package: @ladc/mysql-adapter
Description: Connect to MySQL and MariaDB with the LADC API ('mysql' connector).
Author: Paleo
Latest version: 0.22.15

# @ladc/mysql-adapter

[![Build Status](https://travis-ci.com/paroi-tech/ladc.svg?branch=master)](https://travis-ci.com/paroi-tech/ladc)
[![npm](https://img.shields.io/npm/dm/@ladc/mysql-adapter)](https://www.npmjs.com/package/@ladc/mysql-adapter)
![Type definitions](https://img.shields.io/npm/types/@ladc/mysql-adapter)
[![GitHub](https://img.shields.io/github/license/paroi-tech/ladc)](https://github.com/paroi-tech/ladc)

[LADC](https://github.com/paroi-tech/ladc/tree/master/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](https://www.npmjs.com/package/mysql).

## Install

```
npm install @ladc/mysql-adapter ladc
```

## Use a MySQL connection with LADC

How to create a connection:

```js
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:

```sh
npm install sql-bricks @ladc/sql-bricks-modifier
```

In your code, MySQL requires to set a specific `placeholder` option in SQL Bricks:

```js
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:

```js
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`)
npm package: @ladc/mysql2-adapter
Description: Connect to MySQL and MariaDB with the LADC API ('mysql2' connector).
Author: Paleo
Latest version: 0.22.14

# @ladc/mysql2-adapter

<!-- [![Dependencies Status](https://david-dm.org/paroi-tech/ladc-mysql2-adapter/status.svg)](https://david-dm.org/paroi-tech/ladc-mysql2-adapter)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/732365855c7e452a893b389fa40262c1)](https://www.codacy.com/manual/paroi-tech/ladc-mysql2-adapter?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=paroi-tech/ladc-mysql2-adapter&amp;utm_campaign=Badge_Grade) -->

[![Build Status](https://travis-ci.com/paroi-tech/ladc.svg?branch=master)](https://travis-ci.com/paroi-tech/ladc)
[![npm](https://img.shields.io/npm/dm/@ladc/mysql2-adapter)](https://www.npmjs.com/package/@ladc/mysql2-adapter)
![Type definitions](https://img.shields.io/npm/types/@ladc/mysql2-adapter)
[![GitHub](https://img.shields.io/github/license/paroi-tech/ladc)](https://github.com/paroi-tech/ladc)

[LADC](https://github.com/paroi-tech/ladc/tree/master/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](https://github.com/sidorares/node-mysql2).

## Install

```
npm install @ladc/mysql2-adapter ladc
```

## Use a MySQL connection with LADC

How to create a connection:

```js
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:

```sh
npm install sql-bricks @ladc/sql-bricks-modifier
```

In your code, MySQL requires to set a specific `placeholder` option in SQL Bricks:

```js
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:

```js
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`)
npm package: @ladc/pg-adapter
Description: Connect to Postgresql with the LADC API.
Author: Paleo
Latest version: 0.22.7

# @ladc/pg-adapter

<!-- [![Dependencies Status](https://david-dm.org/paroi-tech/ladc-pg-adapter/status.svg)](https://david-dm.org/paroi-tech/ladc-pg-adapter)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/af6b0c42452d449086625891b86f478c)](https://www.codacy.com/manual/paroi-tech/ladc-pg-adapter?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=paroi-tech/ladc-pg-adapter&amp;utm_campaign=Badge_Grade) -->

[![Build Status](https://travis-ci.com/paroi-tech/ladc.svg?branch=master)](https://travis-ci.com/paroi-tech/ladc)
[![npm](https://img.shields.io/npm/dm/@ladc/pg-adapter)](https://www.npmjs.com/package/@ladc/pg-adapter)
![Type definitions](https://img.shields.io/npm/types/@ladc/pg-adapter)
[![GitHub](https://img.shields.io/github/license/paroi-tech/ladc)](https://github.com/paroi-tech/ladc)

[LADC](https://github.com/paroi-tech/ladc/tree/master/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 Postgresql, using the connector [pg](https://github.com/brianc/node-postgres).

## Install

```sh
npm install @ladc/pg-adapter ladc
```

## Usage

How to create a connection:

```ts
import ladc from "ladc";
import pgAdapter from "@ladc/pg-adapter";

const cn = ladc({
  adapter: pgAdapter({
    pgConfig: {
      host: "-my-server-",
      database: "-my-database-",
      user: "-my-user-",
      password: "-my-password-",
    },
  }),
});
```

## How to Retrieve the Last Inserted Identifier with Postgresql

Postgresql has a gotcha regarding autoincremented identifiers. The insert query must end with a non-standard returning statement. Then, the name of the autoincremented column is required to obtain its last inserted value.

The LADC adapter for Postgresql provides the `autoincMapping` option. It allows to provide a mapping of autoincremented column name for each table that has one. Here is an example:

```js
const autoincMapping = {
  test: "test_id",
};

const cn = ladc({
  adapter: pgAdapter({
    pgConfig: {
      /* credentials */
    },
    autoincMapping,
  }),
});

// The adapter will append 'returning test_id'
const result = await cn.exec(
  "insert into test (message) values ('Hello, World!')"
);

// Returns the value of 'test_id'
const newId = result.getInsertedId();
```

Or, it is still possible to manually write the `returning` statement then to get it:

```js
const result = await cn.exec(
  "insert into test(message) values ('Hi there!') returning test_id" // Postgres only
);
const newId = result.getInsertedId("test_id");
```

## Contribute

With VS Code, our recommanded plugin is:

- **TSLint** from Microsoft (`ms-vscode.vscode-typescript-tslint-plugin`)
npm package: @ladc/sqlite3-adapter
Description: Connect to SQLite with the LADC API.
Author: Paleo
Latest version: 0.22.9

# @ladc/sqlite3-adapter

<!-- [![Dependencies Status](https://david-dm.org/paroi-tech/ladc-sqlite3-adapter/status.svg)](https://david-dm.org/paroi-tech/ladc-sqlite3-adapter)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/b1db8eb8f3754035854abce5758a2fab)](https://www.codacy.com/manual/paroi-tech/ladc-sqlite3-adapter?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=paroi-tech/ladc-sqlite3-adapter&amp;utm_campaign=Badge_Grade) -->

[![Build Status](https://travis-ci.com/paroi-tech/ladc.svg?branch=master)](https://travis-ci.com/paroi-tech/ladc)
[![npm](https://img.shields.io/npm/dm/@ladc/sqlite3-adapter)](https://www.npmjs.com/package/@ladc/sqlite3-adapter)
![Type definitions](https://img.shields.io/npm/types/@ladc/sqlite3-adapter)
[![GitHub](https://img.shields.io/github/license/paroi-tech/ladc)](https://github.com/paroi-tech/ladc)

[LADC](https://github.com/paroi-tech/ladc/tree/master/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 SQLite, using the connector [sqlite3](https://github.com/mapbox/node-sqlite3) (SQLite).

## Install

```
npm install @ladc/sqlite3-adapter ladc
```

## Usage

How to create a connection:

```ts
import ladc from "ladc";
import sqlite3Adapter from "@ladc/sqlite3-adapter";

const cn = ladc({
  adapter: sqlite3Adapter({ fileName: `${__dirname}/mydb.sqlite` }),
  initConnection: async (cn) => {
    await cn.exec("PRAGMA foreign_keys = ON");
  },
});
```

## Contribute

With VS Code, our recommanded plugin is:

- **TSLint** from Microsoft (`ms-vscode.vscode-typescript-tslint-plugin`)