# @twilson63/mysql-down

> [![Build Status](https://travis-ci.org/twilson63/mysql-down.svg?branch=master)](https://travis-ci.org/twilson63/mysql-down)

Latest version **1.1.4** (published 2018-06-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @twilson63/mysql-down
pnpm add @twilson63/mysql-down
yarn add @twilson63/mysql-down
bun add @twilson63/mysql-down
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2018-06-12 |
| First published | 2018-01-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 216.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Tom Wilson |
| Maintainers | twilson63 |

## Links

- npm: https://www.npmjs.com/package/@twilson63/mysql-down
- Repository: https://github.com/twilson63/mysql-down
- Homepage: https://github.com/twilson63/mysql-down#readme
- Issues: https://github.com/twilson63/mysql-down/issues
- npm.io page: https://npm.io/package/@twilson63/mysql-down

## Dependencies (3)

- [mysql](https://npm.io/package/mysql.md) ^2.15.0
- [ramda](https://npm.io/package/ramda.md) ^0.25.0
- [abstract-leveldown](https://npm.io/package/abstract-leveldown.md) ^3.0.0

## Recent versions

- 1.1.4 (latest) — 2018-06-12
- 1.1.3 — 2018-06-12
- 1.1.2 — 2018-06-11
- 1.1.1 — 2018-06-11
- 1.1.0 — 2018-06-11
- 1.0.17 — 2018-05-16
- 1.0.16 — 2018-03-27
- 1.0.15 — 2018-01-23
- 1.0.14 — 2018-01-23
- 1.0.13 — 2018-01-23
- 1.0.12 — 2018-01-23
- 1.0.11 — 2018-01-22
- 1.0.10 — 2018-01-21
- 1.0.9 — 2018-01-21
- 1.0.8 — 2018-01-20
- … 8 more at https://npm.io/package/@twilson63/mysql-down/versions

## README

# twilson63/mysql-down

[![Build Status](https://travis-ci.org/twilson63/mysql-down.svg?branch=master)](https://travis-ci.org/twilson63/mysql-down)

A Level Down Wrapper around MySQL

## Install

```
npm install twilson63/mysql-down
```

## Connections

Connecting to MySQL you have two options:

* Supply a mysql:// uri
* Supply a json:// object

### MySQL URI

When connecting you can supply a connection uri or `[db]/[table]` combination,
if you just supply the db/table then it will assume the connection uri is the
following `mysql://root@localhost:3306/db/table`.

You can also supply the connection uri via env variables

MYSQL_URI=mysql://root@localhost:3306/db?.... node server.js

> If MYSQL_URI is provided, then it will serve as the connection and the location
> will serve as the datastore name

> So if you wanted to connect to remote mysql you would provide the URI via env
> and then call `db = MysqlDOWN('foo')` to represent the table name in the database.

## Example

```
const db = levelup(
  encode(mysqldown('mysql://root@localhost:3306/beep/foo2'), {
    valueEncoding: 'json'
  })
)

db.put(1, { bar: 'bam' }).then(() => {
  db.get(1).then(v => console.log(v.bar))
})

db
  .createReadStream({ gt: 1 })
  .on('data', data => {
    console.log('key', data.key.toString())
    console.log('value', data.value)
  })
  .on('close', function () {
    console.log('it is over now')
  })
```

### MySQL JSON

If you have passwords with slashes in them or use secret stores that store your connection info in a json object, you may want to use a stringified json object as the database name.

Example:

```js
const db = levelup(
  encode(
    mysqldown(
      'json://' +
        JSON.stringify({
          host: 'localhost',
          port: 3306,
          user: 'twilson63a',
          password: 'foo/bar',
          database: 'mydb',
          table: 'foobar'
        })
    ),
    {
      valueEncoding: 'json'
    }
  )
)

db.put(1, { bar: 'bam' }).then(() => {
  db.get(1).then(v => console.log(v.bar))
})

db
  .createReadStream({ gt: 1 })
  .on('data', data => {
    console.log('key', data.key.toString())
    console.log('value', data.value)
  })
  .on('close', function() {
    console.log('it is over now')
  })
```

## SSL Support

### Amazon RDS

SSL Support for Amazon RDS is simple, just add the following environment var

`MYSQL_SSL="Amazon RDS"`

If you are not using Amazon, then you will need to provide an actual ca certificate:

`MYSQL_SSL_CA=[certificate contents]`

See https://github.com/mysqljs/mysql#ssl-options

For more information.

## Testing

Runs the AbstractLevelDOWN Test Suite

```
npm test
```

## Contributions

Welcome

## License

MIT

## Thanks

* [https://github.com/kesla/mysqlDOWN](https://github.com/kesla/mysqlDOWN) from @kesla

* LevelUP and LevelDOWN

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