Skip to content

Latest commit

 

History

History
96 lines (78 loc) · 2.74 KB

datastore.md

File metadata and controls

96 lines (78 loc) · 2.74 KB

Datastore support

Gocrud supports both SQL and NoSQL databases including other datastores. This is how they can be used and initialized in your code.

Cassandra
import "github.com/manishrjain/gocrud/store"
import _ "github.com/manishrjain/gocrud/drivers/cassandra"

func main() {
	// You can use table_cassandra.cql to generate the table.
	// Arguments: ip address, keyspace, table
	store.Get().Init("192.168.59.103", "crudtest", "instructions")
	// OR, if you need authentication, it can also take 5 args, like so:
	// store.Get().Init("192.168.59.103", "crudtest", "instructions", "username", "password")
}
LevelDB
import "github.com/manishrjain/gocrud/store"
import _ "github.com/manishrjain/gocrud/drivers/leveldb"

func main() {
	store.Get().Init("/tmp/ldb_filename")
}
import "github.com/manishrjain/gocrud/store"
import _ "github.com/manishrjain/gocrud/drivers/sqlstore"

func main() {
	// Arguments: store name, connection, table name
	store.Get().Init("mysql", "root@tcp(127.0.0.1:3306)/test", "instructions")
}
PostGreSQL (thanks philips)
import "github.com/manishrjain/gocrud/store"
import _ "github.com/manishrjain/gocrud/drivers/sqlstore"

func main() {
	// Arguments: store name, connection, table name
	store.Get().Init("postgres", "postgres://localhost/test?sslmode=disable", "instructions")
}
Google Datastore
import "github.com/manishrjain/gocrud/store"
import _ "github.com/manishrjain/gocrud/drivers/datastore"

func main() {
	// Arguments: table prefix, google project id.
	store.Get().Init("Test-", "project-id")
}
RethinkDB (thanks dancannon)
import "github.com/manishrjain/gocrud/store"
import _ "github.com/manishrjain/gocrud/drivers/rethinkdb"

func main() {
	// Arguments: IP address with port, database, tablename
	store.Get().Init("192.168.59.103:28015", "test", "instructions")
}
MongoDB (thanks wolfeidau)
import "github.com/manishrjain/gocrud/store"
import _ "github.com/manishrjain/gocrud/drivers/mongodb"

func main() {
	// Arguments: IP address with port, database, tablename
	store.Get().Init("192.168.59.103:27017", "crudtest", "instructions")
}
Any others as requested

Drivers for any other data stores can be easily added by implementing the Store interface below.

type Store interface {
  Init(args ...string)
  Commit(its []*x.Instruction) error
  IsNew(subject string) bool
  GetEntity(subject string) ([]x.Instruction, error)
}

The data is stored in a flat “tuple” format, to allow for horizontal scaling across machines in both SQL and NoSQL databases. Again, no data is ever deleted (Retention principle), to allow for log tracking all the changes.