modulepackage
0.0.0-20241219020713-730da8537660
Repository: https://github.com/gopi-frame/database.git
Documentation: pkg.go.dev
# README
Database
Package database provides a database abstraction client.
This package is based on gorm
Installation
go get -u github.com/gopi-frame/database
Import
import "github.com/gopi-frame/database"
Usage
package main
import (
"github.com/gopi-frame/database"
_ "github.com/gopi-frame/database/sqlite"
// _ "github.com/gopi-frame/database/mysql"
// _ "github.com/gopi-frame/database/postgres"
// _ "github.com/gopi-frame/database/sqlserver"
)
func main() {
db, err := database.Connect("sqlite", map[string]any{
"dsn": "file:test.db",
})
if err!= nil {
panic(err)
}
}
Drivers
How to create a custom driver
To create a custom driver, just implement the database.Driver interface and register it using database.Register.
Example
package main
import (
"github.com/gopi-frame/database"
"gorm.io/gorm"
)
var driverName = "custom"
func init() {
database.Register(driverName, &CustomDriver{})
}
type CustomDriver struct{}
func (d *CustomDriver) Open(options map[string]any) (gorm.Dialector, error) {
var d gorm.Dialector
// implement your driver here
return d, nil
}
# Functions
Connect connects to a database using the given driver name and options.
Drivers returns a list of registered database drivers.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Open opens a new database connector using the given driver name and options.
Register registers a new database driver.
No description provided by the author
# Structs
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author