orm

package module
v0.0.0-...-ab26e33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

README

db-orm

Go Reference License Release Go Test Go Report Card

This package provides configurable factory wrapper of gorm, and with mysql driver bundled.

Usage

package main

import orm "github.com/go-haru/db-orm"

func init() {
    var cfg = orm.Config{
        Driver: "mysql",
        Mysql: orm.MysqlConfig{
            DSN: "mysql:// ........",
        },
    }
    if globalORM, err := orm.Instantiate(&cfg); err != nil {
        // handle error
    }
}

Contributing

For convenience of PM, please commit all issue to Document Repo.

License

This project is licensed under the Apache License Version 2.0.

Use and contributions signify your agreement to honor the terms of this LICENSE.

Commercial support or licensing is conditionally available through organization email.

Documentation

Index

Constants

View Source
const (
	DriverTypeMysql = "mysql"
)

Variables

This section is empty.

Functions

func IsNotFound

func IsNotFound(err error) bool

func NewLogger

func NewLogger(options *loggerOptions) gormLogger.Interface

Types

type Config

type Config struct {
	DryRun      bool          `json:"dryRun" yaml:"dryRun"`
	Migration   bool          `json:"migration" yaml:"migration"`
	UpdateAll   bool          `json:"updateAll" yaml:"updateAll"`
	Driver      string        `json:"driver" yaml:"driver"`
	Prefix      string        `json:"prefix" yaml:"prefix"`
	Mysql       MysqlConfig   `json:"mysql" yaml:"mysql"`
	Logger      loggerOptions `json:"logger" yaml:"logger"`
	PingTimeout Duration      `json:"pingTimeout" yaml:"pingTimeout"`
	// contains filtered or unexported fields
}

func (*Config) Address

func (c *Config) Address() string

type Database

type Database struct {
	// contains filtered or unexported fields
}

func Instantiate

func Instantiate(c *Config, filters ...configFilter) (_ *Database, err error)

func (Database) OrmDB

func (c Database) OrmDB() *gorm.DB

func (Database) SqlDB

func (c Database) SqlDB() *sql.DB

func (Database) Transaction

func (c Database) Transaction(handler func(Database) error, opts *sql.TxOptions) error

type Duration

type Duration int64

func (*Duration) Duration

func (d *Duration) Duration() time.Duration

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(rawBytes []byte) (err error)

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) (err error)

type MysqlConfig

type MysqlConfig struct {
	DSN          string            `json:"dsn" yaml:"dsn"`
	Network      string            `json:"network" yaml:"network"`
	Address      string            `json:"address" yaml:"address"`
	Username     string            `json:"username" yaml:"username"`
	Password     string            `json:"password" yaml:"password"`
	PublicKey    string            `json:"publicKey" yaml:"publicKey"`
	Database     string            `json:"database" yaml:"database"`
	Collation    string            `json:"collation" yaml:"collation"`
	Timezone     string            `json:"timezone" yaml:"timezone"`
	DialTimeout  string            `json:"dailTimeout" yaml:"dailTimeout"`
	ReadTimeout  string            `json:"readTimeout" yaml:"readTimeout"`
	WriteTimeout string            `json:"writeTimeout" yaml:"writeTimeout"`
	NoReadonly   bool              `json:"noReadonly" yaml:"noReadonly"`
	TlsConfig    network.TlsConfig `json:"tls" yaml:"tls"`
	Params       map[string]string `json:"params" yaml:"params"`
}

func (*MysqlConfig) Dialector

func (c *MysqlConfig) Dialector() (gorm.Dialector, string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL