Skip to content

Commit b12d36d

Browse files
committed
GitBook: [master] one page modified
1 parent 96c396c commit b12d36d

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

docs/code-mods/connecting-a-database-using-google-sheets.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,29 @@ You could now access your database in a function like the one below. This functi
8484

8585
Wow. That's seems like a lot of work for such a short dialogue. But now you could have one of 10,000 terms randomly displayed to the user. There will be more examples of functions accessing a database in the listed _Code Mods_.
8686

87-
## 5. Adding more databases
87+
## 5. Using multiple databases
8888

89-
You may want to use multiple databases in your chatbot. You can reuse the `getDB( )` function to load several databases like below, allowing you to access each database with `chatbot.db`, `chatbot.db2`, and `chatbot.db3`.
89+
#### Separate Google Sheets Files
90+
91+
If you want to access multiple Google Sheet files to create multiple databases, you can reuse the `getDB( )` function to load several databases like below. This allows you to access each database with `chatbot.db`, `chatbot.db2`, and `chatbot.db3`.
9092

9193
```javascript
92-
//replace the 'link' text in each to match your spreadsheet link
94+
// replace the 'link' text in each to match your spreadsheet links
95+
// for each Google Sheets file
9396
chatbot.getDB('link').then(data => chatbot.db = data);
94-
chatbot.getDB('link').then(data => chatbot.db2 = data);
95-
chatbot.getDB('link').then(data => chatbot.db3 = data);
97+
chatbot.getDB('link2').then(data => chatbot.db2 = data);
98+
chatbot.getDB('link3').then(data => chatbot.db3 = data);
99+
```
100+
101+
#### One Google Sheets File with Several Sheets
102+
103+
If you want to use a single Google Sheets File that has multiple named sheets, you can use the `getDB( )` function in the following way. Notice that you must include the _sheet name_ along with the _link_ in this case.
104+
105+
```javascript
106+
// replace the 'link' text and 'sheet name' in each to match your spreadsheet link
107+
// and corresponding sheet names
108+
chatbot.getDB('link', 'My First Sheet Name').then(data => chatbot.db = data);
109+
chatbot.getDB('link2', 'My Second Sheet Name').then(data => chatbot.db2 = data);
110+
chatbot.getDB('link3', 'My Third Sheet Name').then(data => chatbot.db3 = data);
96111
```
97112

0 commit comments

Comments
 (0)