Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add and improve examples of connections, queries and more #2337

Merged
merged 29 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
086c65c
chore: prevent large package-lock.json modifications
wellwelwel Jan 4, 2024
33b638e
ci: add unit tests
wellwelwel Jan 4, 2024
78ef347
docs: `SELECT` examples using Prepared Statement
wellwelwel Jan 4, 2024
3f86396
chore: update Docusaurus
wellwelwel Jan 6, 2024
c3b0b81
ci: include unit tests
wellwelwel Jan 6, 2024
4edbefb
ci: check for doc files extensions
wellwelwel Jan 6, 2024
ae64aaf
docs: adapting examples for both JS and TS
wellwelwel Jan 6, 2024
f180582
docs: `INSERT` examples using Prepared Statement
wellwelwel Jan 6, 2024
2705a9e
docs: `UPDATE` examples using Prepared Statement
wellwelwel Jan 6, 2024
b277142
docs: `DELETE` examples using Prepared Statement
wellwelwel Jan 6, 2024
0750e24
docs: fix broken links
wellwelwel Jan 6, 2024
10f6988
ci: throw for broken links
wellwelwel Jan 6, 2024
10e35f8
docs: include tags
wellwelwel Jan 6, 2024
756b2c2
ci: rename website CI and include unit tests
wellwelwel Jan 6, 2024
4349443
docs: `SELECT` query examples
wellwelwel Jan 6, 2024
61ef71f
docs: `INSERT` query examples
wellwelwel Jan 6, 2024
18e7f47
docs: `UPDATE` query examples
wellwelwel Jan 6, 2024
4faaacd
docs: `DELETE` query examples
wellwelwel Jan 6, 2024
ca36246
docs: introduce connection examples
wellwelwel Jan 6, 2024
7661e43
docs: `createConnection` examples
wellwelwel Jan 6, 2024
c1f2f67
docs: `createPool` examples
wellwelwel Jan 6, 2024
685049d
docs: `createPoolCluster` examples
wellwelwel Jan 6, 2024
f7e6526
docs: group queries examples
wellwelwel Jan 6, 2024
c537977
docs: unify, group and reorganize examples
wellwelwel Jan 6, 2024
c4d47bb
docs: fix broken links
wellwelwel Jan 6, 2024
30f7ffc
docs: suggest examples in their respective sections in home
wellwelwel Jan 6, 2024
e08a4c9
docs: add Row as Array query example
wellwelwel Jan 6, 2024
0bfe719
docs: polish examples
wellwelwel Jan 6, 2024
51425d5
docs: add `ExternalCodeEmbed` component to website contributing
wellwelwel Jan 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ jobs:
- name: Checking Types
run: cd website && npm run typecheck

- name: Run Unit Tests
run: cd website && npm run test:unit

- name: Checking Build
run: cd website && npm run build
3 changes: 3 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
- name: Checking Types
run: cd website && npm run typecheck

- name: Run Unit Tests
run: cd website && npm run test:unit

- name: Building Site
run: cd website && npm run build

Expand Down
1 change: 0 additions & 1 deletion website/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/build
/.docusaurus
/.cache-loader
/**/*.mdx
3 changes: 2 additions & 1 deletion website/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"plugin:import/errors",
"plugin:import/warnings",
"plugin:react-hooks/recommended",
"plugin:react/jsx-runtime"
"plugin:react/jsx-runtime",
"plugin:@docusaurus/recommended"
],
"parserOptions": {
"ecmaVersion": "latest",
Expand Down
1 change: 0 additions & 1 deletion website/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
/.docusaurus
/.cache-loader
# /**/*.mdx
package-lock.json
40 changes: 39 additions & 1 deletion website/docs/contributing/website.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ title: Documentation Site
import { FAQ } from '@site/src/components/FAQ';
import { History } from '@site/src/components/History';
import { Stability } from '@site/src/components/Stability';
import { ExternalCodeEmbed } from '@site/src/components/ExternalCodeEmbed';

# Website Contributing Guidelines

Expand Down Expand Up @@ -145,7 +146,8 @@ import { FAQ } from '@site/src/components/FAQ';

- The **FAQ** component can be utilized in any section or page.
- Code blocks are compatible and can be used within the **FAQ** component.
:::

:::

<FAQ title='Example'>
<FAQ title='Title'>
Expand All @@ -157,6 +159,42 @@ import { FAQ } from '@site/src/components/FAQ';

---

### ExternalCodeEmbed

{/* prettier-ignore-start */}
```tsx
import { ExternalCodeEmbed } from '@site/src/components/ExternalCodeEmbed';

<ExternalCodeEmbed
url='https://github.com/sidorares/node-mysql2/blob/75b05f0765c9edd0c0be8f18d85be05618770cca/.prettierrc'
language='json'
/>

<ExternalCodeEmbed
url='https://raw.githubusercontent.com/sidorares/node-mysql2/master/tools/parse-row.js'
language='js'
extractMethod='parseC'
methodType='function'
/>
```
{/* prettier-ignore-end */}

<FAQ title='Example'>
<ExternalCodeEmbed
url='https://raw.githubusercontent.com/sidorares/node-mysql2/master/.prettierrc'
language='json'
/>

<ExternalCodeEmbed
url='https://raw.githubusercontent.com/sidorares/node-mysql2/master/tools/parse-row.js'
language='js'
extractMethod='parseC'
methodType='function'
/>
</FAQ>

---

## Running Tests

```bash
Expand Down
41 changes: 39 additions & 2 deletions website/docs/documentation/prepared-statements.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
tags: [Prepared Statements, execute]
---

# Prepared Statements

## Automatic creation, cached and re-used by connection
Expand Down Expand Up @@ -39,11 +43,11 @@ connection.prepare('select ? + ? as tests', (err, statement) => {

Note that you should not use statement after connection reset (`changeUser()` or disconnect). Statement scope is connection, you need to prepare statement for each new connection in order to use it.

# Configuration
## Configuration

`maxPreparedStatements` : We keep the cached statements in a [lru-cache](https://github.com/isaacs/node-lru-cache). Default size is `16000` but you can use this option to override it. Any statements that are dropped from cache will be `closed`.

# Serialization of bind parameters
## Serialization of bind parameters

The bind parameter values passed to `execute` are serialized JS -> MySQL as:

Expand All @@ -57,3 +61,36 @@ The bind parameter values passed to `execute` are serialized JS -> MySQL as:
- Other -> `VAR_STRING`

Passing in `undefined` or a `function` will result in an error.

## Prepared Statements Helper

MySQL2 provides `execute` helper which will prepare and query the statement. You can also manually prepare / unprepare statement with `prepare` / `unprepare` methods.

```js
connection.execute(
'select ?+1 as qqq, ? as rrr, ? as yyy',
[1, null, 3],
(err, rows, fields) => {
console.log(err, rows, fields);
connection.execute(
'select ?+1 as qqq, ? as rrr, ? as yyy',
[3, null, 3],
(err, rows, fields) => {
console.log(err, rows, fields);
connection.unprepare('select ?+1 as qqq, ? as rrr, ? as yyy');
connection.execute(
'select ?+1 as qqq, ? as rrr, ? as yyy',
[3, null, 3],
(err, rows, fields) => {
console.log(err, rows, fields);
}
);
}
);
}
);
```

## Examples

For Prepared Statements examples, please see [here](http://localhost:3000/node-mysql2/docs/examples/queries/prepared-statements).
2 changes: 1 addition & 1 deletion website/docs/documentation/promise-wrapper.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ co(function* () {
});
```

Examples in [/examples/promise-co-await](/docs/examples/promise-co-await)
Examples in [/examples/promise-co-await](/docs/examples/promise-wrapper/co-await)
4 changes: 2 additions & 2 deletions website/docs/documentation/typescript-examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,10 @@ For `ProcedureCallPacket<RowDataPacket[]>`, please see the following examples.

You can also check some code examples using **MySQL2** and **TypeScript** to understand advanced concepts:

- [Extending and using **Interfaces** with `RowDataPacket`](/docs/examples/typescript/row-data/row-data-packet)
- [Extending and using **Interfaces** with `RowDataPacket`](/docs/examples/typescript/row-data/index)
- [Extending and using **Interfaces** with `RowDataPacket` and `rowAsArray`](/docs/examples/typescript/row-data/row-as-array)
- [Extending and using **Interfaces** with `RowDataPacket` and `multipleStatements`](/docs/examples/typescript/row-data/multi-statements)
- [Extending and using **Interfaces** with `RowDataPacket`, `rowAsArray` and `multipleStatements`](/docs/examples/typescript/row-data/row-as-array-multi-statements)
- [Checking for `ResultSetHeader`, extending and using **Interfaces** with `RowDataPacket` from `ProcedureCallPacket`](/docs/examples/typescript/procedure-call/procedure-call-packet)
- [Checking for `ResultSetHeader`, extending and using **Interfaces** with `RowDataPacket` from `ProcedureCallPacket`](/docs/examples/typescript/procedure-call/index)
- [Checking for `ResultSetHeader`, extending and using **Interfaces** with `RowDataPacket` and `rowAsArray` from `ProcedureCallPacket`](/docs/examples/typescript/procedure-call/row-as-array)
- [Creating a basic custom **MySQL2** **Class**](/docs/examples/typescript/basic-custom-class)
Loading
Loading