Skip to content

Commit 8561597

Browse files
committed
chore(readme): update with usage and options
1 parent e12993b commit 8561597

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

README.md

+20-6
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,38 @@ npm install fastify-at-mysql
1414

1515
## Getting Started
1616

17+
The `fastify-at-mysql` plugin is a wrapper around the `@databases/mysql` package. It exposes the `mysql` property on the Fastify instance.
18+
1719
```js
1820
const Fastify = require('fastify')
1921
const fatsifyMysql = require('fastify-at-mysql')
2022

2123
const fastify = fastify()
2224
fastify.register(fatsifyMysql, {
23-
host: '',
24-
user: '',
25-
password: '',
26-
database: '',
25+
host: process.env.DB_HOST,
26+
user: process.env.DB_USER,
27+
password: process.env.DB_PASS,
28+
database: process.env.DB_NAME,
2729
})
2830

2931
fastify.get('/', async (request, reply) => {
30-
const result = await fastify.mysql.query('SELECT 1 + 1 AS solution')
32+
const result = await fastify.mysql.query('SELECT * FROM contributors')
3133
reply.send(result)
3234
})
3335
```
3436

37+
The `query` method returns a `Promise` that resolves to an array of objects. Each object represents a row in the result set. It wraps the `sql` method from `@databases/mysql` package that prevents SQL injection attacks.
38+
39+
## Options
40+
41+
The plugin accepts the following options:
42+
43+
- `host` - The hostname of the database you are connecting to. (Default: `localhost`)
44+
- `port` - The port number to connect to. (Default: `3306`)
45+
- `user` - The MySQL user to authenticate as.
46+
- `password` - The password of that MySQL user.
47+
- `database` - Name of the database to use for this connection (Optional).
48+
3549
## License
3650

37-
FastifyAtMysql is licensed under the [MIT](LICENSE) license.
51+
**fastify-at-mysql** is licensed under the [MIT](LICENSE) license.

0 commit comments

Comments
 (0)