You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+20-6
Original file line number
Diff line number
Diff line change
@@ -14,24 +14,38 @@ npm install fastify-at-mysql
14
14
15
15
## Getting Started
16
16
17
+
The `fastify-at-mysql` plugin is a wrapper around the `@databases/mysql` package. It exposes the `mysql` property on the Fastify instance.
18
+
17
19
```js
18
20
constFastify=require('fastify')
19
21
constfatsifyMysql=require('fastify-at-mysql')
20
22
21
23
constfastify=fastify()
22
24
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,
27
29
})
28
30
29
31
fastify.get('/', async (request, reply) => {
30
-
constresult=awaitfastify.mysql.query('SELECT 1 + 1 AS solution')
32
+
constresult=awaitfastify.mysql.query('SELECT * FROM contributors')
31
33
reply.send(result)
32
34
})
33
35
```
34
36
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
+
35
49
## License
36
50
37
-
FastifyAtMysql is licensed under the [MIT](LICENSE) license.
51
+
**fastify-at-mysql** is licensed under the [MIT](LICENSE) license.
0 commit comments