Datastore Connectivity in go
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs change createTable signature specification type to interface{} Jan 20, 2019
examples Added ShowCreateTable to dialect Nov 5, 2018
test change createTable signature specification type to interface{} Jan 20, 2019
CHANGELOG.md updated changelog Jan 20, 2019
LICENSE Patched custom mapper with struct pointer case Oct 27, 2016
NOTICE Patched custom mapper with struct pointer case Oct 27, 2016
README.md updated doc Dec 27, 2018
api.go change createTable signature specification type to interface{} Jan 20, 2019
column.go added casandra dialect with API tweaks Nov 29, 2018
common.go Patched custom mapper with struct pointer case Oct 27, 2016
config.go patched setting credential location Jan 8, 2019
config_test.go Patched custom mapper with struct pointer case Oct 27, 2016
connection.go added heleper method for config parameters, patched time issue on fil… Dec 22, 2017
connection_test.go change abstract embeded type to be pointer Feb 24, 2017
cover.out Patched custom mapper with struct pointer case Oct 27, 2016
dialect.go change createTable signature specification type to interface{} Jan 20, 2019
dialect_registry.go corrected typos Jan 8, 2019
dialect_test.go change createTable signature specification type to interface{} Jan 20, 2019
dml_builder.go added batched inserts May 20, 2018
dml_provider.go patched record mapper Oct 3, 2018
doc.go Patched custom mapper with struct pointer case Oct 27, 2016
factory_registry.go added casandra dialect with API tweaks Nov 29, 2018
file_connection.go added heleper method for config parameters, patched time issue on fil… Dec 22, 2017
file_dialect.go minor refactoring Feb 26, 2018
file_dialect_test.go minor refactoring Feb 26, 2018
file_manager.go patched insert batches May 22, 2018
file_manager_factory.go minor refactoring Feb 26, 2018
file_manager_test.go minor refactoring Feb 26, 2018
file_scanner.go updated sql parser with SQLCriteria Feb 28, 2018
logger.go added casandra dialect with API tweaks Nov 29, 2018
manager.go change createTable signature specification type to interface{} Jan 20, 2019
manager_factory.go major refacotring Feb 22, 2018
manager_factory_test.go minor refactoring Feb 26, 2018
manager_registry.go Added ShowCreateTable to dialect Nov 5, 2018
matcher.go Patched custom mapper with struct pointer case Oct 27, 2016
matcher_test.go patched map reading Apr 4, 2017
query_builder.go change createTable signature specification type to interface{} Jan 20, 2019
record_mapper.go Added ShowCreateTable to dialect Nov 5, 2018
scanner.go moved scanner from asc Mar 1, 2018
sql_connection.go added casandra dialect with API tweaks Nov 29, 2018
sql_dialect.go change createTable signature specification type to interface{} Jan 20, 2019
sql_dialect_test.go Added ShowCreateTable to dialect Nov 5, 2018
sql_manager.go change createTable signature specification type to interface{} Jan 20, 2019
sql_manager_factory.go minor refactoring Feb 26, 2018
sql_manager_test.go patche dml bluilder Dec 20, 2017
sql_parser.go change createTable signature specification type to interface{} Jan 20, 2019
sql_parser_test.go change createTable signature specification type to interface{} Jan 20, 2019
sql_predicate.go updated sql parser with SQLCriteria Feb 28, 2018
sql_predicate_test.go updated sql parser with SQLCriteria Feb 28, 2018
sql_scanner.go moved scanner from asc Mar 1, 2018
table_descriptor.go change createTable signature specification type to interface{} Jan 20, 2019
table_descriptor_test.go refactor panic with errro Dec 16, 2017

README.md

Datastore Connectivity (dsc)

Datastore Connectivity library for Go. GoDoc

This library is compatible with Go 1.10+

Please refer to CHANGELOG.md if you encounter breaking changes.

Motivation

This library was developed as part of dsunit (Datastore unit testibility library) to provide unified access to SQL, noSQL, or any other store that deals with structured data in SQL-ish way.

Usage:

The following is a very simple example of CRUD operations with dsc

package main

import (
)


func main() {


	config := dsc.NewConfig("mysql", "[user]:[password]@[url]", "user:root,password:dev,url:tcp(127.0.0.1:3306)/mydb?parseTime=true")
	factory := NewManagerFactory()
	manager, err := factory.Create(config)
    if err != nil {
        panic(err.Error())
	}

    // manager := factory.CreateFromURL("file:///etc/myapp/datastore.json")
  
  
    interest := Interest{}
    
    success, err:= manager.ReadSingle(&interest, SELECT id, name, expiry, category FROM interests WHERE id = ?", []interface{}{id},nil)
	if err != nil {
        panic(err.Error())
	}

    var intersts = make([]Interest, 0)
    err:= manager.ReadAll(&interests, SELECT id, name, expiry, category FROM interests", nil ,nil)
    if err != nil {
        panic(err.Error())
    }

    
    intersts := []Interest {
        Interest{Name:"Abc", ExpiryTimeInSecond:3600, Category:"xyz"},
        Interest{Name:"Def", ExpiryTimeInSecond:3600, Category:"xyz"},
        Interest{Id:20, Name:"Ghi", ExpiryTimeInSecond:3600, Category:"xyz"},
    }


	inserted, updated, err:= manager.PersistAll(&intersts, "interests", nil)
	if err != nil {
        panic(err.Error())
   	}
    deleted, err := manager.DeleteAll(&intersts, "intersts", nil)
    if err != nil {
        panic(err.Error())
   	}
 	fmt.Printf("Inserted %v, updated: %v\n", deleted)
  
}

More examples illustrating the use of the API are located in the examples directory.

Details about the API are available in the docs directory.

Prerequisites

Go version v1.5+ is required.

To install the latest stable version of Go, visit http://golang.org/dl/

Target

Installation:

  1. Install Go 1.5+ and setup your environment as Documented here.
  2. Get the client in your GOPATH : go get github.com/viant/dsc
  • To update the client library: go get -u github.com/viant/dsc

Some Hints:

  • To run a go program directly: go run <filename.go>
  • to build: go build -o <output> <filename.go>

API Documentation

API documentation is available in the docs directory.

Tests

This library is packaged with a number of tests. Tests require Testify library.

Before running the tests, you need to update the dependencies:

$ go get .

To run all the test cases with race detection:

$ go test

Examples

A simple CRUD applications is provided in the examples directory.

GoCover

GoCover

License

The source code is made available under the terms of the Apache License, Version 2, as stated in the file LICENSE.

Individual files may be made available under their own specific license, all compatible with Apache License, Version 2. Please see individual files for details.

Credits and Acknowledgements

Library Author: Adrian Witas

Contributors: Sudhakaran Dharmaraj