Skip to content

The Postgres driver for facades.Orm() of Goravel.

License

Notifications You must be signed in to change notification settings

goravel/postgres

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postgres

The Postgres driver for facades.Orm() of Goravel.

Version

goravel/postgres goravel/framework
v1.0.* v1.16.*

Install

  1. Add package
go get -u github.com/goravel/postgres
  1. Register service provider
// config/app.go
import "github.com/goravel/postgres"

"providers": []foundation.ServiceProvider{
    ...
    &postgres.ServiceProvider{},
}
  1. Add postgres driver to config/database.go file
// config/database.go
import (
    "github.com/goravel/framework/contracts/database"
    "github.com/goravel/framework/contracts/database/orm"
    postgresfacades "github.com/goravel/postgres/facades"
)

"connections": map[string]any{
    ...
    "postgres": map[string]any{
        "host":     config.Env("DB_HOST", "127.0.0.1"),
        "port":     config.Env("DB_PORT", 5432),
        "database": config.Env("DB_DATABASE", "forge"),
        "username": config.Env("DB_USERNAME", ""),
        "password": config.Env("DB_PASSWORD", ""),
        "sslmode":  "disable",
        "timezone": "UTC", // Asia/Shanghai
        "prefix":   "",
        "singular": false,
        "via": func() (orm.Driver, error) {
            return postgresfacades.Postgres("postgres"), nil
        },
        // Optional
        "read": []database.Config{
            {Host: "192.168.1.1", Port: 3306, Database: "forge", Username: "root", Password: "123123"},
        },
        // Optional
        "write": []database.Config{
            {Host: "192.168.1.2", Port: 3306, Database: "forge", Username: "root", Password: "123123"},
        },
    },
}

About

The Postgres driver for facades.Orm() of Goravel.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages