Golang based database realization
Example project of database realization using drivers and models
- Go 1.17+;
- $go test
config := database.LoadConfig("database.cfg")
driver, err := database.NewDriver(database.FILE_DRIVER)
if err != nil {
log.Fatal(err)
}
err = driver.Configure(config)
if err != nil {
log.Fatal(err)
}
connection, err := driver.Connect()
if err != nil {
log.Fatal(err)
}
// Read . . .
// Iterate . . .
// Write . . .
defer connection.Disconnect()
// var driver database.IDriver (FileDriver)
// var query database.IQuery (FileQuery)
defer driver.Disconnect()
row := driver.ReadRow("users", query)
row.SetCol("name", "John")
driver.WriteRow(row)
// var driver database.IDriver (FileDriver)
// var query database::IQuery
query := driver.NewQuery()
query.Select("users", "*")
query.From("users")
query.Where("users", "id", "=", "1")
// var row database.Row
row := query.GetRow()
fmt.Println("user name is ", row.GetCol("name"))