https://github.com/omarghader/multidb
One interface, multiple databases
https://github.com/omarghader/multidb
arangodb golang mongodb mysql neo4j postgresql
Last synced: 6 months ago
JSON representation
One interface, multiple databases
- Host: GitHub
- URL: https://github.com/omarghader/multidb
- Owner: omarghader
- Created: 2019-03-14T12:27:20.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-10-22T21:07:28.000Z (over 5 years ago)
- Last Synced: 2024-06-21T02:15:38.994Z (about 2 years ago)
- Topics: arangodb, golang, mongodb, mysql, neo4j, postgresql
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# multidb
The aim of this library is to make one interface for multiple databases.
# Todo :
* Relational DB
* [ ] MySQL
* [ ] PostgreSql
* NoSQL DB
* [ ] Mongodb
* [ ] Arangodb
* Graph DB
* [ ] Neo4j
* [x] Arangodb
# Example
```go
db := arangodb.NewArangodb(multidb.ConnectionOptions{
Host: "localhost",
Port: "8529",
Username: "root",
Password: "root",
DBName: "db",
})
db.Create()
// Create a table
db.Table("table_test").Create()
// Insert documents
type DocTest struct {
Key string `json:"_key,omitempty"`
ID string `json:"_id,omitempty"`
Name string
}
doc1 := DocTest{Key: "doc1", Name: "document1"}
var doc1Res DocTest
db.Table("table_test").Insert(doc1, &doc1Res)
doc2 := DocTest{Key: "doc2", Name: "document2"}
var doc2Res DocTest
db.Table("table_test").Insert(doc2, &doc2Res)
// Create a graph
db.Graph("graph_test").Create()
// Create relation
db.Graph("graph_test").Relation("is_related").Insert(
arangodb.Edge{
From: doc1Res.ID,
To: doc2Res.ID,
}, map[string]interface{}{"prop1": "friend"})
```
# API
```go
type Database interface {
Create() error
Exists() bool
Drop() error
Table(name string) Table
Graph(name string) Graph
ExecQuery(query string, params map[string]interface{}, res []interface{}) ([]interface{}, error)
}
// Collection or table
type Table interface {
Create() error
Exists() bool
Drop() error
CRUD
}
type Graph interface {
Create() error
Relation(name string) Relation
}
type Relation interface {
Insert(data interface{}, res interface{}) (interface{}, error)
Find(id string, res interface{}) (interface{}, error)
Update(id string, data interface{}, res interface{}) (interface{}, error)
Delete(id string, res interface{}) (interface{}, error)
}
type CRUD interface {
Insert(data interface{}, res interface{}) (interface{}, error)
Find(id string, res interface{}) (interface{}, error)
Update(id string, data interface{}, res interface{}) (interface{}, error)
Delete(id string, res interface{}) (interface{}, error)
}