Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit ab4a15e

Browse files
authored
Merge pull request #60 from codeoverflow-org/223-sql
Add sample doc for SQL service
2 parents 7f3c4b3 + bd0454d commit ab4a15e

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ If that's no problem you can head over to the [installation guide](./getting_sta
4141
- [x] Serial Port (Arduino)
4242
- [x] Slack WebAPI
4343
- [x] Spotify
44+
- [x] SQL (using [knex](https://knexjs.org/))
4445
- [x] Elgato Stream Deck
4546
- [x] StreamElements
4647
- [x] Telegram

docs/samples/sql.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## Using the SQL sample bundle
2+
3+
The SQL example bundle in `samples/sql` demonstrates the ability to access databases. Here is a guide to how to get it working.
4+
5+
### Prerequisites
6+
7+
- Working NodeCG & nodecg-io installation
8+
- A database supported by [knex](https://knexjs.org/#Installation)
9+
10+
_Note:_ If you don't have a database yet and just want to test things you can use sqlite3 and don't need to setup a database server. You can always move to a different database type later.
11+
12+
### Configure the SQL sample bundle
13+
14+
1. Start nodecg with nodecg-io installed. The SQL sample bundle is currently part of it so it should also be loaded.
15+
16+
2. Go to the `nodecg-io` tab in the nodecg dashboard.
17+
18+
3. Login using your password. If this is your first run, then enter the password with which you want to encrypt your configurations and credentials.
19+
20+
4. Create a new SQL service instance using the left upper menu.
21+
22+
5. Enter configuration for SQL.
23+
24+
The created instance should be automatically selected, if not select it in the upper left menu. Enter your used database client and a [knex connection object](https://knexjs.org/#Installation-client) in monaco (the text-editor on the right) in this format:
25+
26+
```json
27+
{
28+
"client": "mysql",
29+
"connection": {
30+
"host": "localhost",
31+
...
32+
}
33+
}
34+
```
35+
36+
After entering it, click save.
37+
38+
_Note:_ If you don't see monaco on the right, try reloading the page.
39+
40+
6. Set the created SQL service instance to the service dependency of the SQL sample bundle.
41+
42+
Select the SQL sample bundle and the SQL service in the left bottom menu and then select the service instance that should be used by the SQL sample bundle (in this case the name of the previously created SQL instance).
43+
44+
7. Check the nodecg logs
45+
46+
Your first run of the sample bundle will probably fail because your database doesn't contain the used tables.
47+
Check `samples/sql/extension/index.ts` and create the tables as used or create your own tables and adapt the sample accordingly.
48+
You can also use this code as a reference on how to use the sql client to do your queries.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ nav:
6868
- Serial sample: samples/serial.md
6969
- Slack sample: samples/slack.md
7070
- Spotify sample: samples/spotify.md
71+
- SQL sample: samples/sql.md
7172
- Streamdeck sample: samples/streamdeck.md
7273
- StreamElements sample: samples/streamelements.md
7374
- Telegram sample: samples/telegram.md

0 commit comments

Comments
 (0)