Command line tool for Google Cloud Datastore, written in Go

dsio

dsio is a command line tool for Google Cloud Datastore.

This tool is under development. Please use in your own risk.

Features

  • Bulk upsert entities from CSV and YAML file.
  • Query by GQL from command line.

Motivation

I have been developing web application which uses Datastore to store application's master data. I want to version-control master data in Datastore, and want to automatically reflect the changes to Datastore using CI service.
like below:

ci

Getting Started

Installation

go get -u github.com/nshmura/dsio

Authentication

  1. Create a service account.
  2. Set the following environment variable:
  • DSIO_KEY_FILE : The path to the JSON key file.
  • DSIO_PROJECT_ID : Developers Console project's ID (e.g. bamboo-shift-455)

Or execute dsio command with --key-file and --project-id options:

$ dsio upsert --key-file <path-to-service_account_file> --project-id <project-id> ...

How to connect to Datastore Emulator

If you want to connect to local Datastore emnulator, execute below command:

$(gcloud beta emulators datastore env-init)

For more information, please see this document.

Bulk Upsert

To upsert entities from CSV file to Datastore: (e.g. upsert into Book kind)

$ dsio upsert filename.csv -k Book

To upsert entities from YAML file to Datastore:

$ dsio upsert filename.yaml

To specify namespace:

$ dsio upsert filename.yaml -n development

File format and Samples:

Query by GQL

To query by GQL:

$ dsio query 'SELECT * FROM Book LIMIT 2'

Output with CSV format:

$ dsio query 'SELECT * FROM Book LIMIT 2' -f csv

To specify namespace (e.g. production namespace):

$ dsio query 'SELECT * FROM Book LIMIT 2' -n production 

CAUTION: In CSV (and TSV) format, information about types may be dropped in some case, and noindex value is removed. So in some case, there is no way to restore exactly same entities in Datastore from the generated CSV.

Options

dsio upsert

$ dsio help upsert

NAME:
   dsio upsert - Bulk-upsert entities into Datastore.

USAGE:
   dsio upsert [command options] filename

OPTIONS:
   --namespace value, -n value  namespace of entities.
   --kind value, -k value       Name of destination kind.
   --format value, -f value     Format of input file. <yaml|csv|tcv>. (default: "yaml")
   --dry-run                    Skip Datastore operations.
   --batch-size value           The number of entities per one multi upsert operation. batch-size should be smaller than 500. (default: 500)
   --key-file value             name of GCP service account file. [$DSIO_KEY_FILE]
   --project-id value           Project ID of GCP. [$DSIO_PROJECT_ID]
   --verbose, -v                Make the operation more talkative.
   --no-color                   Disable color output.

dsio query

$ dsio help query

NAME:
   dsio query - Execute a query.

USAGE:
   dsio query [command options] "[<gql_query>]"

OPTIONS:
   --namespace value, -n value  namespace of entities.
   --output value, -o value     Output filename. Entities are outputed into this file.
   --format value, -f value     Format of output. <yaml|csv|tcv>. (default: "yaml")
   --style value, -s value      Style of output. <scheme|direct|auto>. (default: "scheme")
   --page-size value            Number of entities to output at once. (default: 50)
   --key-file value             name of GCP service account file. [$DSIO_KEY_FILE]
   --project-id value           Project ID of GCP. [$DSIO_PROJECT_ID]
   --verbose, -v                Make the operation more talkative.
   --no-color                   Disable color output.
Owner
Shinichi Nishimura
Backend Software Engineer
Shinichi Nishimura
Comments
  • dsio query throwing error -> Missing or insufficient permissions.

    dsio query throwing error -> Missing or insufficient permissions.

    I have set up the project and added the necessary environment variables to use the "dsio query" operation. But when I use it for a Select query, it always throws the following error

    rpc error: code = PermissionDenied desc = Missing or insufficient permissions.

    This is happening despite the fact that I have full access to the project that I am trying to run the query against. Am I missing something?

  • Automatic completion for blank integer

    Automatic completion for blank integer

    When I directly import the same data that not changed from when they parsed with SELECT query, it alerts: [ERROR] can not parse 'strconv.ParseInt: parsing "": invalid syntax' as int.

    But I expected the integer-typed blank values would be automatically converted to 0.

  • Update README.md with info about the Docker image

    Update README.md with info about the Docker image

    I've created a Docker image with dsio, which I've used for work and personal stuff. I thought it could be useful for non-developers or developers that don't have a Go environment ready on their machines.

  • Can't install dsio with go get

    Can't install dsio with go get

    Hi, When I tried installing with go get as explained in the readme, I get this:

    ➜  dsio go get -u github.com/nshmura/dsio
    
    # github.com/nshmura/dsio/core
    ../go/src/github.com/nshmura/dsio/core/log.go:41:45: undefined: cli.ExitError
    ../go/src/github.com/nshmura/dsio/core/context.go:23:20: c.GlobalBool undefined (type *cli.Context has no field or method GlobalBool)
    
  • Convert from glide to go modules

    Convert from glide to go modules

    go get -u github.com/nshmura/dsio fails with the following error:

    ❯ go get -u github.com/nshmura/dsio
    # github.com/nshmura/dsio/core
    .gvm/pkgsets/go1.15/global/src/github.com/nshmura/dsio/core/context.go:23:19: c.GlobalBool undefined (type *cli.Context has no field or method GlobalBool)
    .gvm/pkgsets/go1.15/global/src/github.com/nshmura/dsio/core/log.go:41:41: undefined: cli.ExitError
    

    go env

    ❯ go env
    GO111MODULE=""
    GOARCH="amd64"
    GOBIN=""
    GOCACHE="/home/laurence/.cache/go-build"
    GOENV="/home/laurence/.config/go/env"
    GOEXE=""
    GOFLAGS=""
    GOHOSTARCH="amd64"
    GOHOSTOS="linux"
    GOINSECURE=""
    GOMODCACHE="/home/laurence/.gvm/pkgsets/go1.15/global/pkg/mod"
    GONOPROXY="github.com/paymentsense/*"
    GONOSUMDB="github.com/paymentsense/*"
    GOOS="linux"
    GOPATH="/home/laurence/.gvm/pkgsets/go1.15/global"
    GOPRIVATE="github.com/paymentsense/*"
    GOPROXY="https://proxy.golang.org,direct"
    GOROOT="/home/laurence/.gvm/gos/go1.15"
    GOSUMDB="sum.golang.org"
    GOTMPDIR=""
    GOTOOLDIR="/home/laurence/.gvm/gos/go1.15/pkg/tool/linux_amd64"
    GCCGO="gccgo"
    AR="ar"
    CC="gcc"
    CXX="g++"
    CGO_ENABLED="1"
    GOMOD=""
    CGO_CFLAGS="-g -O2"
    CGO_CPPFLAGS=""
    CGO_CXXFLAGS="-g -O2"
    CGO_FFLAGS="-g -O2"
    CGO_LDFLAGS="-g -O2"
    PKG_CONFIG="pkg-config"
    GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build518681876=/tmp/go-build -gno-record-gcc-switches"
    

    In order to fix this, all I've needed to do is convert the project to go modules

  • Support time.RFC3339Nano format & Use go.mod

    Support time.RFC3339Nano format & Use go.mod

    Cloud Datastore DateTime can store up to microsecond precision. [1] So I think it is better to support the precision.

    [1] https://cloud.google.com/datastore/docs/concepts/entities?hl=en#date_and_time

  • Fix support for equality query on key field

    Fix support for equality query on key field

    An equality check for a key field was failing with a panic if the optional project and namespace were not supplied, and with a datastore client error if they were provided.

    Panic output was:

    panic: interface conversion: gql.Expression is nil, not string
    
    goroutine 1 [running]:
    github.com/nshmura/dsio/gql.(*yyParserImpl).Parse(0xc0002daa80, 0xbbbae0, 0xc0002e2ac0, 0x0)
    	yaccpar:735 +0x549b
    github.com/nshmura/dsio/gql.yyParse(...)
    	yaccpar:153
    github.com/nshmura/dsio/gql.(*Lexer).Parse(0xc0002e2ac0, 0xc00030a520, 0x1000)
    	parser.go.y:737 +0x5e
    github.com/nshmura/dsio/action.parseGQL(0x7fff97a33dcd, 0x60, 0xc0002632a0, 0x448b8e, 0xc0000bdab2)
    	/home/james/dev/go/pkg/mod/github.com/nshmura/[email protected]/action/query.go:102 +0x1d6
    github.com/nshmura/dsio/action.getKindQuery(0x7fff97a33d09, 0x54, 0x7fff97a33d6b, 0x19, 0x7fff97a33d91, 0xf, 0x0, 0x7fff97a33dcd, 0x60, 0xa411376f0f80abb6, ...)
    	/home/james/dev/go/pkg/mod/github.com/nshmura/[email protected]/action/query.go:85 +0x3f
    github.com/nshmura/dsio/action.Query(0x7fff97a33d09, 0x54, 0x7fff97a33d6b, 0x19, 0x7fff97a33d91, 0xf, 0x0, 0x7fff97a33dcd, 0x60, 0x7fff97a33daa, ...)
    	/home/james/dev/go/pkg/mod/github.com/nshmura/[email protected]/action/query.go:45 +0xc7
    main.main.func2(0xc0000eb340, 0x0, 0xc000282ab0)
    	/home/james/dev/go/pkg/mod/github.com/nshmura/[email protected]/dsio.go:175 +0x33f
    github.com/urfave/cli.HandleAction(0x9e8d40, 0xb10b38, 0xc0000eb340, 0xc0000eb340, 0x0)
    	/home/james/dev/go/pkg/mod/github.com/urfave/[email protected]/app.go:523 +0xbe
    github.com/urfave/cli.Command.Run(0xae0a6c, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0xae7db4, 0x10, 0x0, ...)
    	/home/james/dev/go/pkg/mod/github.com/urfave/[email protected]/command.go:174 +0x51c
    github.com/urfave/cli.(*App).Run(0xc0003001c0, 0xc0000c6000, 0xf, 0xf, 0x0, 0x0)
    	/home/james/dev/go/pkg/mod/github.com/urfave/[email protected]/app.go:276 +0x725
    main.main()
    	/home/james/dev/go/pkg/mod/github.com/nshmura/[email protected]/dsio.go:184 +0xa80
    

    Datastore error was:

    [ERROR] datastore: bad query filter value type: invalid Value type gql.KeyLiteralExpr
    

    The first is fixed by defaulting the project and namespace to an empty string if not specified (a string cannot be set to nil).

    The latter is fixed by translating the gql.KeyLiteralExpr into a datastore.Key in the equality branch of the query building.

    It's not clear from the datastore client docs what one should do with the project ID if it is specified in the KEY(...) GQL expression, so this is left unimplemented at present.

  • Cannot handle data with space

    Cannot handle data with space

    I'm not sure whether that's really the cause of the error to be honest. I installed your CLI and tried to import the list of french postal codes from CSV file but I get an error on the first line. Here is my command: DSIO_KEY_FILE=./service-account.json DSIO_PROJECT_ID=my-project-id dsio upsert ~/Downloads/insee.csv -k postalCodes

    The CSV file is: https://raw.githubusercontent.com/Rudloff/french-postal-codes-api/master/insee.csv.

    I'm on OSX 10.14.2. Here is the error message I get: image

    The CSV doesn't seem to be misformatted so I don't see what could be the problem.

    Hope it helps to find if there is something to be fixed on your end.

Rclone ("rsync for cloud storage") is a command line program to sync files and directories to and from different cloud storage providers.
Rclone (

Rclone ("rsync for cloud storage") is a command line program to sync files and directories to and from different cloud storage providers.

Jan 5, 2023
Rclone ("rsync for cloud storage") is a command-line program to sync files and directories to and from different cloud storage providers.
Rclone (

Website | Documentation | Download | Contributing | Changelog | Installation | Forum Rclone Rclone ("rsync for cloud storage") is a command-line progr

Nov 5, 2021
An open-source GitLab command line tool bringing GitLab's cool features to your command line
An open-source GitLab command line tool bringing GitLab's cool features to your command line

GLab is an open source GitLab CLI tool bringing GitLab to your terminal next to where you are already working with git and your code without switching

Dec 30, 2022
A command line tool to prompt for a value to be included in another command line.

readval is a command line tool which is designed for one specific purpose—to prompt for a value to be included in another command line. readval prints

Dec 22, 2021
GC2 is a Command and Control application that allows an attacker to execute commands on the target machine using Google Sheet and exfiltrate data using Google Drive.
GC2 is a Command and Control application that allows an attacker to execute commands on the target machine using Google Sheet and exfiltrate data using Google Drive.

GC2 GC2 (Google Command and Control) is a Command and Control application that allows an attacker to execute commands on the target machine using Goog

Dec 13, 2022
e2d is a command-line tool for deploying and managing etcd clusters, both in the cloud or on bare-metal

e2d is a command-line tool for deploying and managing etcd clusters, both in the cloud or on bare-metal. It also includes e2db, an ORM-like abstraction for working with etcd.

Aug 23, 2022
fofax is a fofa query tool written in go, positioned as a command-line tool and characterized by simplicity and speed.
fofax is a fofa query tool written in go, positioned as a command-line tool and characterized by simplicity and speed.

fofaX 0x00 Introduction fofax is a fofa query tool written in go, positioned as

Jan 8, 2023
A CLI tool which loads data from yaml files into the Google Cloud Spanner tables

splanter A CLI tool which loads data from yaml files into the Google Cloud Spanner tables (mainly for the development).

Oct 27, 2022
git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.
git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.

Table of contents Introduction Reference Contributing Introduction Overview git-xargs is a command-line tool (CLI) for making updates across multiple

Dec 31, 2022
git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command
git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command

git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command. You give git-xargs:

Feb 5, 2022
A command line tool for simplified docker volume command built with go

dockervol A command line tool for simplified docker volume command built with go. Features: Remove anonymous volume (beta) Remove volume by matching n

Dec 18, 2021
Command Line Interface for Terraform Enterprise/Cloud ( tecli )
Command Line Interface for Terraform Enterprise/Cloud ( tecli )

In a world where everything is Terraform, teams use Terraform Cloud API to manage their workloads. TECLI increases teams productivity by facilitating such interaction and by providing easy commands that can be executed on a terminal or on CI/CD systems.

Dec 16, 2022
A tool to enumerate all the command-line arguments used to start a Linux process written in Go.
A tool to enumerate all the command-line arguments used to start a Linux process written in Go.

ranwith A tool to enumerate all the command-line arguments used to start a Linux process written in Go. ranwith uses the Linux /proc directory to obta

Jun 30, 2022
🖼️ A command-line system information tool written in bash 3.2+
🖼️  A command-line system information tool written in bash 3.2+

A command-line system information tool written in bash 3.2+ Neofetch is a command-line system information tool written in bash 3.2+. Neofetch displays

Dec 30, 2022
F2 is a cross-platform command-line tool for batch renaming files and directories quickly and safely. Written in Go!
F2 is a cross-platform command-line tool for batch renaming files and directories quickly and safely. Written in Go!

F2 is a cross-platform command-line tool for batch renaming files and directories quickly and safely.

Dec 31, 2022
Gofetch is a pretty command-line "Go and System information" tool written in Go
Gofetch is a pretty command-line

GoFetch Show off your Go information with this cool command-line tool! Report Bug || Request Feature Table of Contents About the Project Built With Ge

Nov 1, 2022
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.

asciigraph Go package to make lightweight ASCII line graphs ╭┈╯. Installation go get github.com/guptarohit/asciigraph Usage Basic graph package main

Jan 8, 2023
Package command provide simple API to create modern command-line interface

Package command Package command provide simple API to create modern command-line interface, mainly for lightweight usage, inspired by cobra Usage pack

Jan 16, 2022
Watcher - A simple command line app to watch files in a directory for changes and run a command when files change!

Watcher - Develop your programs easily Watcher watches all the files present in the directory it is run from of the directory that is specified while

Mar 27, 2022