Skip to content

mookjp/yakiire

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔥🔥🔥 yakiire 🔥🔥🔥

CircleCI

yakiire (yaki-ire; 焼入れ) is a CLI to manage and operate data on GCP Firestore.

THIS IS THE ALPHA VERSION !!

Contents

Installation

go get github.com/mookjp/yakiire

Configuration

yakiire needs environment variables:

ENV value required
YAKIIRE_FIRESTORE_PROJECT_ID Firestore project ID Yes
YAKIIRE_GOOGLE_APPLICATION_CREDENTIALS GCP's credential file path No

If YAKIIRE_GOOGLE_APPLICATION_CREDENTIALS was not set, yakiire uses GOOGLE_APPLICATION_CREDENTIALS to access to Firestore.

Usage

Get

yakiire get -c <collection name> <document ID>

e.g.

$ yakiire get -c products 002VQIDE4D

# it shows a doc in JSON format

{"Attributes":{"color":"red","size":"100"},"CategoryIDs":["1","2","3"],"ID":"002VQIDE4D","Name":"Test Product"}

It is handy to use jq to check the result from the command.

$ yakiire get -c products 002VQIDE4D | tail -n 1 | jq .

{
  "Attributes": {
    "color": "red",
    "size": "100"
  },
  "CategoryIDs": [
    "1",
    "2",
    "3"
  ],
  "ID": "002VQIDE4D",
  "Name": "Test Product"
}

Query

yakiire query --collection products \
    --where '{"Path": "Attributes.size", "Op": ">", "Value": 0}' \
    --where '{"Path": "Attributes.color", "Op": "==", "Value": "red"}' \
    --limit 1

e.g.

yakiire query --collection products \
    --where '{"Path": "Attributes.size", "Op": ">", "Value": 0}'

# it shows docs in line-delimited JSON format

{"Attributes":{"color":"red","size":100},"CategoryIDs":["1","2","3"],"ID":"1","Name":"Test Product"}
{"Attributes":{"color":"red","size":200},"CategoryIDs":["1","2","3"],"ID":"2","Name":"Another Test Product"}

yakiire query --collection products \
    --where '{"Path": "Attributes.size", "Op": ">", "Value": 0}' \
    --limit 1

# limit to 1 result
# default number of limit is 20

{"Attributes":{"color":"red","size":100},"CategoryIDs":["1","2","3"],"ID":"1","Name":"Test Product"}

yakiire query --collection products \
    --where '{"Path": "Attributes.size", "Op": ">", "Value": 0}' \
    --where '{"Path": "CategoryIDs", "Op": "array-contains", "Value": "1"}' \
    --limit 1

# multiple where conditions

{"Attributes":{"color":"red","size":100},"CategoryIDs":["1","2","3"],"ID":"1","Name":"Test Product"}

Add

yakiire add -c <collection name> <json string>

e.g.

yakiire add --collection products '{"Attributes":{"color":"red","size":"100"},"CategoryIDs":["1","2","3"],"ID":"002VQIDE4D","Name":"Test Product"}'

# it shows the doc in JSON format if added successfully

{"Attributes":{"color":"red","size":"100"},"CategoryIDs":["1","2","3"],"ID":"002VQIDE4D","Name":"Test Product"}

Delete

yakiire delete -c <collection name> <document ID>

e.g.

yakiire delete --collection products 002VQIDE4D

# No output is returned if the document is deleted or does not exist (default firestore behavior)

TODOs

Set

yakiire set -c <collection name> <query>

For development

Run tests

FIRESTORE_EMULATOR_HOST=localhost:8080 make test

Test needs running Firestore emulator and it can be run with docker-compose. in Makefile, test will start firestore emulator container before it starts tests.