Coder Social home page Coder Social logo

dsutil's Introduction

dsutil - Google Cloud DataStore import/export utilities

Build Status

Installing

go get github.com/rustyx/dsutil

Command Line Usage

dsutil [options] command <args>

  command:
    export <filename>          - export records from DataStore
    import <filename>...       - import records into DataStore
    delete                     - delete records from DataStore
    set <field> <type> <value> - update records in DataStore (type is: string, int, double)
    convert <in> <out>         - convert exported records from JSON to Go object notation
  Note: <filename> ending with ".gz" will be automatically g(un)zipped

  -project string
    	Google Cloud project name (deduced if not provided)
  -kind string
    	DataStore table name (required for export)
  -filter string
    	Filter field name (optional)
  -from string
    	Filter >= value (optional)
  -to string
    	Filter < value (optional)
  -eq string
    	Filter = value (optional)

API Usage

It is possible to read an export file and process each entity programmatically.

There are two interfaces: ImportFile, based on key-value pairs, and ImportFileReflect, which is useful for ORM. Here's an example of how to load an export file into a PostgreSQL database using go-pg ORM API:

type MyEntity struct {
	Id          int    `datastore:"-"`
	SomeColumn  string `pg:"type:varchar(40)"`
	SomeColumn2 string `pg:"type:varchar(40)"`
	// . . .
}

	inputFile := "my-export.ds"
	log.Printf("Importing %v", inputFile)
	insertFunc := func(kind string, rows []interface{}) error {
		log.Printf("Inserting %v %s(s)", len(rows), kind)
		_, err := pgdb.Model(rows...).Insert()
		return err
	}
	modelMap := []dsio.ModelMapping{
		{Kind: "MyEntity", TypePtr: &MyEntity{}, ImportFunc: insertFunc, BatchSize: 200},
	}
	if err := dsio.ImportFileReflect(inputFile, modelMap); err != nil {
		log.Fatalf("import %v failed: %v", inputFile, err)
	}

For more documentation refer to API Docs.

dsutil's People

Contributors

dependabot[bot] avatar rustyx avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.