Skip to content

Commit b7840ac

Browse files
committed
Enhance README and add Issue Templates.
1 parent 3c6a058 commit b7840ac

File tree

7 files changed

+116
-7
lines changed

7 files changed

+116
-7
lines changed

.github/ISSUE_TEMPLATE/BUG_REPORT.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Bug Report
3+
about: Create a bug report to help us improve
4+
title: ''
5+
labels: 'bug'
6+
assignees: ''
7+
8+
---
9+
10+
<!--
11+
Thank you for filing an issue to make FirestoreGoogleAppsScript better.
12+
Please fill in as much of the template below as you're able.
13+
-->
14+
15+
## Minimal code to reproduce the problem
16+
```javascript
17+
const firestore = FirestoreApp.getFirestore(email, key, projectId);
18+
19+
```
20+
21+
## Expected Behavior
22+
23+
24+
## Actual Results
25+
26+
27+
##### Library Version:
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Feature Request
3+
about: Suggest an idea for this library
4+
title: ''
5+
labels: 'enhancement'
6+
assignees: ''
7+
8+
---
9+
10+
<!--
11+
Thank you for filing an issue to make FirestoreGoogleAppsScript better.
12+
Please fill in as much of the template below as you're able.
13+
-->
14+
15+
## Is your feature request related to a problem?
16+
<!-- Describe the problem you are trying to solve. -->
17+
18+
19+
## Describe the solution you'd like
20+
<!-- Describe the desired behavior, and include code samples and other documentation. -->
21+
22+
23+
## Describe alternatives you've considered
24+
<!-- Describe alternative solutions or features you have considered. -->
25+
26+
27+
## Additional context
28+
<!-- Add any other context or screenshots about the feature request here. -->

.github/ISSUE_TEMPLATE/QUESTION.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
name: "Question / Help"
3+
about: Any questions not clarified by existing issues or documentation
4+
title: ''
5+
labels: 'question'
6+
assignees: ''
7+
8+
---
9+
10+
<!--
11+
Thank you for filing an issue to make FirestoreGoogleAppsScript better.
12+
Please fill in as much of the template below as you're able.
13+
Questions filed here will get better visibility by maintainers than StackOverflow.
14+
-->
15+
16+
## Minimal Code to Reproduce the Problem
17+
```javascript
18+
const firestore = FirestoreApp.getFirestore(email, key, projectId);
19+
20+
```
21+
22+
## Explain the Problem in Detail
23+
<!-- Please be specific as possible. Use dashes (-) or numbers (1.) to create a list of steps -->
24+
25+
26+
### Other Comments
27+
28+
29+
##### Library Version:

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
blank_issues_enabled: false
2+
contact_links:

.github/README.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Read how this project was started [here](http://grahamearley.website/blog/2017/1
1919
As of **v27**, this project has been updated to use the [GAS V8 runtime](https://developers.google.com/apps-script/guides/v8-runtime) with [Typescript](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html)! This introduces a number of [breaking changes](#breaking-changes).
2020

2121
## Installation
22-
In the Google online script editor, select the `Resources` menu item and choose `Libraries...`. In the "Add a library" input box, enter `1VUSl4b1r1eoNcRWotZM3e87ygkxvXltOgyDZhixqncz9lQ3MjfT1iKFw` and click "Add." Choose the most recent version number.
22+
In the Google online script editor, select the `Resources` menu item and choose `Libraries...`. In the "Add a library" input box, enter **`1VUSl4b1r1eoNcRWotZM3e87ygkxvXltOgyDZhixqncz9lQ3MjfT1iKFw`** and click "Add." Choose the most recent version number.
2323

2424

2525
## Quick start
@@ -34,14 +34,33 @@ To make a service account,
3434
3. For your service account's role, choose `Datastore > Cloud Datastore Owner`.
3535
4. Check the "Furnish a new private key" box and select JSON as your key type.
3636
5. When you press "Create," your browser will download a `.json` file with your private key (`private_key`), service account email (`client_email`), and project ID (`project_id`). Copy these values into your Google Apps Script — you'll need them to authenticate with Firestore.
37+
6. **[Bonus]** It is considered best practice to make use of the [Properties Service](https://developers.google.com/apps-script/guides/properties) to store this sensitive information.
3738

38-
#### Create a test document in Firestore from your script
39+
#### Configurating Firestore instance from your script
3940
Now, with your service account client email address `email`, private key `key`, project ID `projectId`, we will authenticate with Firestore to get our `Firestore` object. To do this, get the `Firestore` object from the library:
4041

4142
```javascript
4243
const firestore = FirestoreApp.getFirestore(email, key, projectId);
4344
```
4445

46+
##### Configuration Template
47+
Here's a quick template to get you started (by replacing `email` and `key` with your values):
48+
```javascript
49+
const email = 'projectname-12345@appspot.gserviceaccount.com';
50+
const key = '-----BEGIN PRIVATE KEY-----\nPrivateKeyLine1\nPrivateKeyLine2\nPrivateKeyLineN\n-----END PRIVATE KEY-----';
51+
const projectId = 'projectname-12345'
52+
const firestore = FirestoreApp.getFirestore(email, key, projectId);
53+
```
54+
55+
Alternatively, using [Properties Service](https://developers.google.com/apps-script/guides/properties) <ins>once data is already stored</ins> in the service with **"client_email"**, **"private_key"**, and **"project_id"** property names:
56+
```javascript
57+
const props = PropertiesService.getUserProperties(); // Or .getScriptProperties() if stored in Script Properties
58+
const [email, key, projectId] = [props.getProperty('client_email'), props.getProperty('private_key'), props.getProperty('project_id')];
59+
const firestore = FirestoreApp.getFirestore(email, key, projectId);
60+
```
61+
62+
63+
##### Creating Documents
4564
Using this Firestore instance, we will create a Firestore document with a field `name` with value `test!`. Let's encode this as a JSON object:
4665

4766
```javascript
@@ -50,17 +69,18 @@ const data = {
5069
}
5170
```
5271

53-
We can choose to create a document in collection called `FirstCollection` without a name (Firestore will generate one):
72+
We can choose to create a document in collection called **"FirstCollection"** without a name (Firestore will generate one):
5473

5574
```javascript
5675
firestore.createDocument("FirstCollection", data);
5776
```
5877

59-
Alternatively, we can create the document in the `FirstCollection` collection called `FirstDocument`:
78+
Alternatively, we can create the document in the **"FirstCollection"** collection called **"FirstDocument"**:
6079
```javascript
6180
firestore.createDocument("FirstCollection/FirstDocument", data);
6281
```
6382

83+
##### Updating Documents
6484
To update (overwrite) the document at this location, we can use the `updateDocument` function:
6585
```javascript
6686
firestore.updateDocument("FirstCollection/FirstDocument", data);
@@ -71,6 +91,8 @@ To update only specific fields of a document at this location, we can set the `m
7191
firestore.updateDocument("FirstCollection/FirstDocument", data, true);
7292
```
7393

94+
95+
##### Getting Documents
7496
You can retrieve documents by calling the `getDocument` function:
7597

7698
```javascript
@@ -90,7 +112,8 @@ You can also get specific documents by providing an array of document names
90112
const someDocuments = firestore.getDocuments("FirstCollection", ["Doc1", "Doc2", "Doc3"]);
91113
```
92114

93-
If more specific queries need to be performed, you can use the `query` function followed by an `Execute` invocation to get that data:
115+
##### Getting Documents (Advanced method using Query)
116+
If more specific queries need to be performed, you can use the `query` function followed by an `.Execute()` invocation to get that data:
94117

95118
```javascript
96119
const allDocumentsWithTest = firestore.query("FirstCollection").Where("name", "==", "Test!").Execute();

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "firestore_google-apps-script",
3-
"version": "1.0.29",
3+
"version": "1.0.30",
44
"description": "A Google Apps Script library for accessing Google Cloud Firestore",
55
"homepage": "https://github.com/grahamearley/FirestoreGoogleAppsScript",
66
"bugs": "https://github.com/grahamearley/FirestoreGoogleAppsScript/issues",

0 commit comments

Comments
 (0)