Files
storage/postgres
2020-11-05 05:57:14 +01:00
..
2020-11-05 04:17:05 +01:00
2020-11-05 05:57:14 +01:00
2020-11-05 05:55:18 +01:00
2020-11-04 20:49:53 +01:00

Postgres

A Postgres storage driver using lib/pq.

Table of Contents

Signatures

func New(config ...Config) Storage

Examples

Import the storage package.

import "github.com/gofiber/storage/postgres"

You can use the following possibilities to create a storage:

// Initialize default config
store := postgres.New()

// Initialize custom config
store := postgres.New(postgres.Config{
	GCInterval:      10 * time.Second,
	Host:            "127.0.0.1",
	Port:            5432,
	Database:        "fiber",
	TableName:       "fiber",
	DropTable:       false,
})

Config

// Config defines the config for storage.
type Config struct {
	// Time before deleting expired keys
	//
	// Default is 10 * time.Second
	GCInterval time.Duration

	// DB host
	//
	// Optional. Default is "127.0.0.1"
	Host string

	// DB port
	//
	// Optional. Default is "5432"
	Port int64

	// DB user name
	//
	// Optional. Default is ""
	Username string

	// DB user password
	//
	// Optional. Default is ""
	Password string

	// DB name
	//
	// Optional. Default is "fiber"
	Database string

	// DB table name
	//
	// Optional. Default is "fiber"
	TableName string

	// Drop any existing table with the same name
	//
	// Optional. Default is false
	DropTable bool
}

Default Config

var ConfigDefault = Config{
	GCInterval:      10 * time.Second,
	Host:            "127.0.0.1",
	Port:            5432,
	Database:        "fiber",
	TableName:       "fiber",
	DropTable:       false,
}