# @openfn/language-mysql

> A MySQL Language Pack for OpenFn

Latest version **4.1.3** (published 2026-09-03) · LGPLv3 license · 0 weekly downloads

## Install

```sh
npm install @openfn/language-mysql
pnpm add @openfn/language-mysql
yarn add @openfn/language-mysql
bun add @openfn/language-mysql
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.1.3 |
| Published | 2026-09-03 |
| First published | 2021-07-02 |
| Weekly downloads | 0 |
| License | LGPLv3 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 95.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Open Function Group |
| Maintainers | elias-ba, stuartc-openfn, taylordowns2000, mtuchi, jclark-openfn |

## Links

- npm: https://www.npmjs.com/package/@openfn/language-mysql
- Repository: https://github.com/openfn/adaptors
- Homepage: https://docs.openfn.org
- Issues: https://github.com/openfn/adaptors/issues
- npm.io page: https://npm.io/package/@openfn/language-mysql

## Dependencies (3)

- [knex](https://npm.io/package/knex.md) ^3.1.0
- [mysql2](https://npm.io/package/mysql2.md) ^3.23.1
- [@openfn/language-common](https://npm.io/package/@openfn/language-common.md) 3.3.5

## Recent versions

- 4.1.3 (latest) — 2026-09-03
- 4.1.2 — 2026-06-30
- 4.1.1 — 2026-05-27
- 4.1.0 — 2026-05-21
- 4.0.6 — 2026-05-20
- 4.0.5 — 2026-04-07
- 4.0.4 — 2026-03-30
- 4.0.3 — 2026-02-24
- 4.0.2 — 2026-01-30
- 4.0.1 — 2025-12-03
- 4.0.0 — 2025-12-02
- 3.0.6 — 2025-11-28
- 3.0.5 — 2025-11-12
- 3.0.4 — 2025-10-29
- 3.0.3 — 2025-10-16
- … 47 more at https://npm.io/package/@openfn/language-mysql/versions

## README

# Language MySQL

Language Pack for building expressions and operations to run MySQL queries.

## Documentation

View the [docs site](https://docs.openfn.org/adaptors/packages/mysql-docs) for
full technical documentation.

### Configuration

View all the required and optional properties for `state.configuration` in the
official
[configuration-schema](https://docs.openfn.org/adaptors/packages/mysql-configuration-schema/)
definition.

## Execute a query

Execute an sql query with the node mysql package.

```js
query({
  sql: state => {
    return `select * from ${state.data.table} where id = ?;`;
  },
  timeout: 4000,
  values: ['007'],
});
```

## Execute a sql query

This function takes either a `string` or a `function` that takes states and
returns a string.

```js
sqlString(state => {
  return (
    `INSERT INTO untitled_table (name, the_geom) VALUES ('` +
    state.data.version +
    `', ` +
    dataValue('form.Choix_tache')(state) +
    `)`
  );
});
```

## Insert a single record

This function is used to insert a single record in a MySQL database.

```js
insert(
  'some_table',
  fields(
    field('firstname', dataValue('form.patient_firstname')),
    field('lastname', dataValue('form.patient_lastname'))
  )
);
```

## Insert or update a single record

This function is used to insert a single record in a MySQL database or update it
if there is a match.

```js
upsert(
  'some_table',
  fields(
    field('firstname', dataValue('form.patient_firstname')),
    field('lastname', dataValue('form.patient_lastname'))
  )
);
```

## Upsert many records

This function allows the upsert of a set of records inside a table all at once.

```js
upsertMany(
  'users', // the DB table
  [
    { name: 'one', email: 'one@openfn.org' },
    { name: 'two', email: 'two@openfn.org' },
  ]
);
```

or

```js
upsertMany('users', state =>
  state.data.users.map(user => {
    name: user['name'],
    email: user['email']
  })
);
```

## Development

Clone the [adaptors monorepo](https://github.com/OpenFn/adaptors). Follow the
`Getting Started` guide inside to get set up.

Run tests using `pnpm run test` or `pnpm run test:watch`

Build the project using `pnpm build`.

To just build the docs run `pnpm build docs`

---
_Source: https://npm.io/package/@openfn/language-mysql · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
