Categorygithub.com/timt-unity3d/dsc
modulepackage
0.16.0
Repository: https://github.com/timt-unity3d/dsc.git
Documentation: pkg.go.dev

# README

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

# Packages

No description provided by the author

# Functions

GetDatastoreDialect returns DatastoreDialect for passed in driver.
GetManagerFactory returns a manager factory for passed in driver, or error.
NewAbstractConnection create a new abstract connection.
NewAbstractConnectionProvider create a new AbstractConnectionProvider.
NewAbstractManager create a new abstract manager, it takes config, conneciton provider, and target (sub class) manager.
NewBooleanPredicate returns a new boolean predicate.
NewColumn create new TableColumn.
NewColumnarRecordMapper creates a new ColumnarRecordMapper, to map a data record to slice.
NewConfig creates new Config, it takes the following parameters descriptor - optional datastore connection string with macros that will be looked epxanded from for instance [user]:[password]@[url] encodedParameters should be in the following format: <key1>:<value1>, ...,<keyN>:<valueN>.
NewConfigFromUrl returns new config from url.
NewConfigWithParameters creates a new config with parameters.
NewDefaultDialect crates a defulat dialect.
NewDmlBuilder returns a new DmlBuilder for passed in table descriptor.
NewDmlParser creates a new NewDmlParser.
NewDmlProviderIfNeeded returns a new NewDmlProvider for a table and target type if passed provider was nil.
NewFileManager creates a new file manager.
NewFileScanner create a new file scanner, it takes config, and columns as parameters.
NewKeyGetterIfNeeded returns a new key getter if supplied keyGetter was nil for the target type.
NewLimiter creates a new limiter.
NewManagerFactory create a new manager factory.
NewManagerRegistry create a new ManagerRegistry.
No description provided by the author
NewMapRecordMapper creates a new ColumnarRecordMapper, to map a data record to slice.
NewMetaRecordMapped creates a new MetaRecordMapped to map a data record to a struct, it takes target struct and flag if it is a pointer as parameters.
NewQueryBuilder create anew QueryBuilder, it takes table descriptor and optional query hit to include it in the queries.
NewQueryParser represents basic SQL query parser.
NewRecordMapper create a new record mapper, if struct is passed it would be MetaRecordMapper, or for slice ColumnRecordMapper.
NewRecordMapperIfNeeded create a new mapper if passed in mapper is nil.
No description provided by the author
NewSimpleColumn create simple TableColumn name.
NewSQLCriteriaPredicate create a new sql criteria predicate, it takes binding parameters iterator, and actual criteria.
NewSQLCriterionPredicate create a new predicate for passed in SQLCriterion.
NewSQLDatastoreDialect creates a new default sql dialect.
NewSQLResult returns a new SqlResult.
NewSQLScanner creates a new sql scanner.
NewSQLScannerWithTypes create a scanner with type.
NewTableDescriptor creates a new table descriptor for passed in instance, it can use the following tags:"column", "dateLayout","dateFormat", "autoincrement", "primaryKey", "sequence", "transient".
newTableDescriptorRegistry returns a new newTableDescriptorRegistry.
RegisterDatastoreDialect register DatastoreDialect for a driver.
RegisterManagerFactory registers manager factory for passed in driver.
ScanRow takes scanner to scans row.
StdoutLogger represents stdout logger.
VoidLogger represent logger that do not log.

# Constants

BatchSizeKey represents a config batch size parameter.
SQLTypeDelete 2 constant for DML delete statement provider.
SQLTypeInsert 0 constant for DML insert statement provider.
SQLTypeUpdate 1 constant for DML update statement provider.

# Variables

No description provided by the author
No description provided by the author
Logf - function to log debug info.
No description provided by the author

# Structs

AbstractConnection represents an abstract connection.
AbstractConnectionProvider represents an abstract/superclass ConnectionProvider.
AbstractManager represent general abstraction for datastore implementation.
BaseStatement represents a base query and dml statement.
Config represent datastore config.
No description provided by the author
No description provided by the author
DmlBuilder represents a insert,update,delete statement builder.
DmlParser represents dml parser.
DmlStatement represents dml statement.
FileManager represents a line delimiter, JSON file manager.
FileScanner represents a file scanner to transfer record to destinations.
Limiter represents resource limter.
ParametrizedSQL represents a parmetrized SQL with its binding values, in order of occurrence.
QueryBuilder represetns a query builder.
QueryParser represents a simple SQL query parser.
QueryStatement represents SQL query statement.
SQLColumn represents a sql column.
SQLCriteria represents SQL criteria.
SQLCriterion represents single where clause condiction.
No description provided by the author
No description provided by the author
TableDescriptor represents a table details.

# Interfaces

Column represents TableColumn type interface (compabible with *sql.ColumnType.
No description provided by the author
ColumnValueProvider provides column values.
Connection represents a datastore connection.
ConnectionProvider represents a datastore connection provider.
DatastoreDialect represents datastore dialects.
DmlProvider represents dml generator, which is responsible for providing parametrized sql, it takes operation type:SqlTypeInsert = 0SqlTypeUpdate = 1SqlTypeDelete = 2 and instance to the application abstraction.
KeyGetter represents id/key accessor.
KeySetter represents id/key mutator.
Manager represents datastore manager.
ManagerFactory represents a manager factory.
ManagerRegistry represents a manager registry.
RecordMapper represents a datastore record mapper, it is responsible for mapping data record into application abstraction.
Scanner represents a datastore data scanner.
TableDescriptorRegistry represents a registry to store table descriptors by table name.
TransactionManager represents a transaction manager.

# Type aliases

Log represent log function.