Skip to content

go-gorm/postgres

Folders and files

NameName
Last commit message
Last commit date
Feb 1, 2024
Apr 21, 2023
Jun 2, 2020
Mar 8, 2021
May 8, 2024
May 8, 2024
Mar 10, 2025
Mar 10, 2025
Mar 26, 2025
Oct 26, 2023
Mar 10, 2025
Mar 10, 2025

Repository files navigation

GORM PostgreSQL Driver

Quick Start

import (
  "gorm.io/driver/postgres"
  "gorm.io/gorm"
)

// https://github.com/jackc/pgx
dsn := "host=localhost user=gorm password=gorm dbname=gorm port=9920 sslmode=disable TimeZone=Asia/Shanghai"
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})

Configuration

import (
  "gorm.io/driver/postgres"
  "gorm.io/gorm"
)

db, err := gorm.Open(postgres.New(postgres.Config{
  DSN: "host=localhost user=gorm password=gorm dbname=gorm port=9920 sslmode=disable TimeZone=Asia/Shanghai", // data source name, refer https://github.com/jackc/pgx
  PreferSimpleProtocol: true, // disables implicit prepared statement usage. By default pgx automatically uses the extended protocol
}), &gorm.Config{})

Checkout https://gorm.io for details.