Skip to content

Commit

Permalink
docs: migrate examples
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel committed Nov 25, 2023
1 parent be9213a commit 72dc786
Show file tree
Hide file tree
Showing 60 changed files with 1,738 additions and 31 deletions.
10 changes: 10 additions & 0 deletions website/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@
],
"no-unused-vars": 2
}
},
{
"files": ["static/**/*"],
"rules": {
"import/no-unresolved": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-unused-vars": "off",
"no-unused-vars": "off",
"no-bitwise": "off"
}
}
],
"settings": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# Introduction
---
slug: /documentation
title: Introduction
---

import { PageTitle } from '@site/src/components/PageTitle';

<PageTitle title='Documentation' />

MySQL2 aims to be a drop in replacement for [node-mysql](https://github.com/mysqljs/mysql). Please check `node-mysql` for full documentation.
# Documentation

**Note :** _If you see any API incompatibilities with `node-mysql`, please report via github issue._
MySQL2 aims to be a drop in replacement for [node-mysql](https://github.com/mysqljs/mysql).

:::note
_If you see any API incompatibilities with `node-mysql`, please report via github issue._
:::

Not only `Node-MySQL2` offers better performance over `node-mysql`, we also support these additional features.

Expand All @@ -20,7 +31,7 @@ Not only `Node-MySQL2` offers better performance over `node-mysql`, we also supp

## Examples

Please check these [examples](/docs/examples) for `node-mysql2`.
Please check these [examples](/docs/examples) for **MySQL2**.

---

Expand Down
142 changes: 132 additions & 10 deletions website/docs/examples/index.mdx → website/docs/examples/00-index.mdx
Original file line number Diff line number Diff line change
@@ -1,36 +1,120 @@
---
title: Quickstart
slug: /examples
title: Introduction
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import { PageTitle } from '@site/src/components/PageTitle';

<PageTitle title='Examples' />

# Examples

## Simple SELECT
## Simple `SELECT`

<Tabs>
<TabItem value='Promise' default>

```js
import mysql from 'mysql2/promise';

const connection = await mysql.createConnection({
user: 'test',
database: 'test',
});

const [rows] = await connection.query('SELECT 1+1 AS `test1`');
// ...
```

</TabItem>
<TabItem value='Callback'>

```js
const mysql = require('mysql2');
const connection = mysql.createConnection({ user: 'test', database: 'test' });

connection.query('SELECT 1+1 as test1', (err, rows) => {
//
const connection = mysql.createConnection({
user: 'test',
database: 'test',
});

connection.query('SELECT 1+1 AS `test1`', (err, rows) => {
// ...
});
```

## Prepared statement and parameters
</TabItem>
</Tabs>

---

## Prepared Statement and Parameters

<Tabs>
<TabItem value='Promise' default>

```js
import mysql from 'mysql2/promise';

const connection = await mysql.createConnection({
user: 'test',
database: 'test',
});

const [rows] = await connection.execute('SELECT 1+? AS `test1`', [10]);
// ...
```

</TabItem>
<TabItem value='Callback'>

```js
const mysql = require('mysql2');
const connection = mysql.createConnection({ user: 'test', database: 'test' });

const connection = mysql.createConnection({
user: 'test',
database: 'test',
});

connection.execute('SELECT 1+? as test1', [10], (err, rows) => {
//
// ...
});
```

</TabItem>
</Tabs>

---

## Connecting over encrypted connection

<Tabs>
<TabItem value='Promise' default>

```js
import fs from 'fs';
import mysql from 'mysql2/promise';

const connection = await mysql.createConnection({
user: 'test',
database: 'test',
ssl: {
key: fs.readFileSync('./certs/client-key.pem'),
cert: fs.readFileSync('./certs/client-cert.pem'),
},
});

console.log(await connection.query('SELECT 1+1 AS `test1`'));
```

</TabItem>
<TabItem value='Callback'>

```js
const fs = require('fs');
const mysql = require('mysql2');

const connection = mysql.createConnection({
user: 'test',
database: 'test',
Expand All @@ -39,26 +123,62 @@ const connection = mysql.createConnection({
cert: fs.readFileSync('./certs/client-cert.pem'),
},
});
connection.query('SELECT 1+1 as test1', console.log);

connection.query('SELECT 1+1 AS `test1`', console.log);
```

</TabItem>
</Tabs>

You can use 'Amazon RDS' string as value to ssl property to connect to Amazon RDS mysql over ssl (in that case http://s3.amazonaws.com/rds-downloads/mysql-ssl-ca-cert.pem CA cert is used)

<Tabs>
<TabItem value='Promise' default>

```js
import mysql from 'mysql2/promise';

try {
const connection = await mysql.createConnection({
user: 'foo',
password: 'bar',
host: 'db.id.ap-southeast-2.rds.amazonaws.com',
ssl: 'Amazon RDS',
});

const [res] = await connection.query("SHOW `status` LIKE 'Ssl_cipher'");

console.log(res);
connection.end();
} catch (err) {
console.log(err);
}
```

</TabItem>
<TabItem value='Callback'>

```js
const mysql = require('mysql2');

const connection = mysql.createConnection({
user: 'foo',
password: 'bar',
host: 'db.id.ap-southeast-2.rds.amazonaws.com',
ssl: 'Amazon RDS',
});

connection.query("show status like 'Ssl_cipher'", (err, res) => {
connection.query("SHOW `status` LIKE 'Ssl_cipher'", (err, res) => {
console.log(err, res);
connection.end();
});
```

</TabItem>
</Tabs>

---

## Simple MySQL proxy server

```js
Expand Down Expand Up @@ -115,6 +235,8 @@ server.on('connection', (conn) => {
});
```

---

## Examples using MySQL server API

- [MySQL-pg-proxy](https://github.com/sidorares/mysql-pg-proxy) - MySQL to Postgres proxy server.
Expand Down
11 changes: 11 additions & 0 deletions website/docs/examples/binlog-watcher.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import { ExternalCodeEmbed } from '@site/src/components/ExternalCodeEmbed';

# Binlog Watcher

<Tabs>
<TabItem value='index.js' default>
<ExternalCodeEmbed url='/examples/binlog-watcher.js' language='js' />
</TabItem>
</Tabs>
11 changes: 11 additions & 0 deletions website/docs/examples/connect-over-socks.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import { ExternalCodeEmbed } from '@site/src/components/ExternalCodeEmbed';

# Connect Over Socks

<Tabs>
<TabItem value='index.js' default>
<ExternalCodeEmbed url='/examples/connect-over-socks.js' language='js' />
</TabItem>
</Tabs>
11 changes: 11 additions & 0 deletions website/docs/examples/execute.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import { ExternalCodeEmbed } from '@site/src/components/ExternalCodeEmbed';

# Execute

<Tabs>
<TabItem value='index.js' default>
<ExternalCodeEmbed url='/examples/execute.js' language='js' />
</TabItem>
</Tabs>
11 changes: 11 additions & 0 deletions website/docs/examples/mysqlproxy.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import { ExternalCodeEmbed } from '@site/src/components/ExternalCodeEmbed';

# MySQL Proxy

<Tabs>
<TabItem value='index.js' default>
<ExternalCodeEmbed url='/examples/mysqlproxy.js' language='js' />
</TabItem>
</Tabs>
11 changes: 11 additions & 0 deletions website/docs/examples/pass-sha.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import { ExternalCodeEmbed } from '@site/src/components/ExternalCodeEmbed';

# Pass SHA

<Tabs>
<TabItem value='index.js' default>
<ExternalCodeEmbed url='/examples/pass-sha.js' language='js' />
</TabItem>
</Tabs>
11 changes: 11 additions & 0 deletions website/docs/examples/pool-test.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import { ExternalCodeEmbed } from '@site/src/components/ExternalCodeEmbed';

# Pool Test

<Tabs>
<TabItem value='index.js' default>
<ExternalCodeEmbed url='/examples/pool-test.js' language='js' />
</TabItem>
</Tabs>
11 changes: 11 additions & 0 deletions website/docs/examples/prepare.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import { ExternalCodeEmbed } from '@site/src/components/ExternalCodeEmbed';

# MySQL Proxy

<Tabs>
<TabItem value='index.js' default>
<ExternalCodeEmbed url='/examples/prepare.js' language='js' />
</TabItem>
</Tabs>
29 changes: 29 additions & 0 deletions website/docs/examples/promise-co-await.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import { ExternalCodeEmbed } from '@site/src/components/ExternalCodeEmbed';

# Promise CO Await

<Tabs>
<TabItem value='await.js' default>
<ExternalCodeEmbed
url='/examples/promise-co-await/await.js'
language='js'
/>
</TabItem>
<TabItem value='co.js' default>
<ExternalCodeEmbed url='/examples/promise-co-await/co.js' language='js' />
</TabItem>
<TabItem value='.babelrc' default>
<ExternalCodeEmbed
url='/examples/promise-co-await/babelrc.json'
language='js'
/>
</TabItem>
<TabItem value='package.json' default>
<ExternalCodeEmbed
url='/examples/promise-co-await/package.json'
language='js'
/>
</TabItem>
</Tabs>
6 changes: 6 additions & 0 deletions website/docs/examples/queries/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"label": "Queries",
"link": {
"type": "generated-index"
}
}
11 changes: 11 additions & 0 deletions website/docs/examples/queries/select.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import { ExternalCodeEmbed } from '@site/src/components/ExternalCodeEmbed';

# SELECT

<Tabs>
<TabItem value='index.js' default>
<ExternalCodeEmbed url='/examples/queries/select.js' language='js' />
</TabItem>
</Tabs>
11 changes: 11 additions & 0 deletions website/docs/examples/server.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import { ExternalCodeEmbed } from '@site/src/components/ExternalCodeEmbed';

# Server

<Tabs>
<TabItem value='index.js' default>
<ExternalCodeEmbed url='/examples/server.js' language='js' />
</TabItem>
</Tabs>
Loading

0 comments on commit 72dc786

Please sign in to comment.