postgres

package module
v0.0.0-...-55fdd88 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 9 Imported by: 0

README

Postgres

Go Reference Test driver postgres codecov Go Report Card

Package postgres provides postgres database driver.

Installation

go get -u github.com/gopi-frame/database/postgres

Import

import _ "github.com/gopi-frame/database/postgres"

Usage

package main

import (
	"github.com/gopi-frame/database"
	
	_ "github.com/gopi-frame/database/postgres"
)

func main() {
	db, err := database.Connect("postgres", map[string]any{
		"dsn": "user=postgres password=password dbname=postgres sslmode=disable",
    }),
	if err!= nil {
		panic(err)
	}
}

Options

This package uses package mapstructure to parse options.

For more information on the options, see postgres.Config.

Example
var options = map[string]any{
	"dsn": "user=postgres password=password dbname=postgres sslmode=disable",
	"WithoutQuotingCheck": true,
}

Documentation

Overview

Package postgres provides postgres database driver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(options map[string]any) (*gorm.DB, error)

func Open

func Open(options map[string]any) (gorm.Dialector, error)

Open is a convenience function that calls Driver.Open.

Types

type Connector

type Connector struct {
	DriverName              string
	DSN                     string
	Host                    string
	Port                    int
	HostAddr                []string
	Username                string
	Password                string
	Passfile                string
	Database                string
	RequireAuth             string
	ChannelBinding          string
	ConnectTimeout          time.Duration
	SSLMode                 string
	Timezone                string
	ClientEncoding          string
	Options                 string
	ApplicationName         string
	FallbackApplicationName string
	KeepAlives              bool
	KeepAlivesIdle          time.Duration
	KeepAlivesInterval      time.Duration
	KeepAlivesCount         int
	TCPUserTimeout          time.Duration
	Replication             string
	GSSEncMode              string
	SSLNegotiation          string
	SSLCompression          bool
	SSLCert                 string
	SSLKey                  string
	SSLPassword             string
	SSLCertMode             string
	SSLRootCert             string
	SSLCrl                  string
	SSLCrlDir               string
	SSLSni                  bool
	RequirePeer             string
	SSLMinProtocolVersion   string
	SSLMaxProtocolVersion   string
	KrbSrvName              string
	GSSLib                  string
	GSSDelegation           bool
	Service                 string
	TargetSessionAttrs      string
	LoadBalanceHosts        string
	WithoutQuotingCheck     bool
	PreferSimpleProtocol    bool
	WithoutReturning        bool
	GormOptions             *gorm.Config
	Replicas                []map[string]any
}

func NewConnector

func NewConnector(config map[string]any) (*Connector, error)

func (*Connector) Connect

func (c *Connector) Connect() (*gorm.DB, error)

func (*Connector) GetDSN

func (c *Connector) GetDSN() string

GetDSN returns the DSN.

func (*Connector) Open

func (c *Connector) Open() gorm.Dialector

type Driver

type Driver struct{}

Driver is a postgres database driver.

func (Driver) Connect

func (Driver) Connect(options map[string]any) (*gorm.DB, error)

func (Driver) Open

func (Driver) Open(options map[string]any) (gorm.Dialector, error)

Open opens a postgres database connector. For more information on the options, see postgres.Config(https://pkg.go.dev/gorm.io/driver/postgres#Config).

Jump to

Keyboard shortcuts

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