A library on go to access easily some databases. The main rule of this library is to follow a unique interface for all databases that we implemented. So, you will only need to know one library (easydb) for accessing many databases.
Download
go get github.com/ednailson/easydb-go
The main principle of the library is the database interface.
Every implemented database follows this interface after created.
There is a New(...params)
function for every database, and all of them there is
their own config struct param. This function will return a database interface,
so after that it will be the same usage for every database.
Check how to use it below.
We will create a mongoDB instance right now but you can created an instance of any easydb implemented database.
config := mongo.Config {
Host: "mongodb.service.com.br",
Port: 27017,
Database: "easydb_test",
Username: "root",
Password: "dummyPass",
}
db, err := mongo.NewDatabase(config)
table, err := db.Table("easydb-table-example")
Now you can write or read from this table
writer := table.Writer()
writer.Save(`{"data": "your data"}`)
reader := table.Reader()
reader.Read("document-id")