[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-10436":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":21,"hasPages":21,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":32,"readmeContent":33,"aiSummary":34,"trendingCount":16,"starSnapshotCount":16,"syncStatus":35,"lastSyncTime":36,"discoverSource":37},10436,"pg","go-pg\u002Fpg","go-pg","Golang ORM with focus on PostgreSQL features and performance","https:\u002F\u002Fpg.uptrace.dev\u002F",null,"Go",5787,414,80,112,0,1,7,38.85,"BSD 2-Clause \"Simplified\" License",false,"v10",[24,25,26,27,28,29,30,31],"database","go","golang","hstore","jsonb","orm","postgresql","sql","2026-06-12 02:02:21","# PostgreSQL client and ORM for Golang\n\n## Maintenance mode\n\ngo-pg is in a maintenance mode and only critical issues are addressed. New development happens in\n[**Bun**](https:\u002F\u002Fbun.uptrace.dev\u002Fguide\u002Fpg-migration.html) repo which offers similar functionality\nbut works with PostgreSQL, MySQL, MariaDB, and SQLite.\n\n## [Golang ORM](https:\u002F\u002Fgithub.com\u002Fuptrace\u002Fbun)\n\n---\n\n[![Go](https:\u002F\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Factions\u002Fworkflows\u002Fbuild.yml\u002Fbadge.svg?branch=v10)](https:\u002F\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Factions\u002Fworkflows\u002Fbuild.yml)\n[![PkgGoDev](https:\u002F\u002Fpkg.go.dev\u002Fbadge\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10)](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10)\n[![Documentation](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpg-documentation-informational)](https:\u002F\u002Fpg.uptrace.dev\u002F)\n[![Chat](https:\u002F\u002Fdiscordapp.com\u002Fapi\u002Fguilds\u002F752070105847955518\u002Fwidget.png)](https:\u002F\u002Fdiscord.gg\u002FrWtp5Aj)\n\n- [Documentation](https:\u002F\u002Fpg.uptrace.dev)\n- [Reference](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc)\n- [Examples](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#pkg-examples)\n- Example projects:\n  - [monetr](https:\u002F\u002Fgithub.com\u002Fmonetr\u002Fmonetr) - budgeting application focused on planning for\n    recurring expenses\n  - [bunrouter](https:\u002F\u002Fgithub.com\u002Fgo-bun\u002Fbun-realworld-app)\n  - [gin](https:\u002F\u002Fgithub.com\u002Fgogjango\u002Fgjango)\n  - [go-kit](https:\u002F\u002Fgithub.com\u002FTsovak\u002Frest-api-demo)\n  - [aah framework](https:\u002F\u002Fgithub.com\u002Fkieusonlam\u002Fgolamapi)\n\n## Tutorials\n\n- [GraphQL Tutorial on YouTube](https:\u002F\u002Fwww.youtube.com\u002Fplaylist?list=PLzQWIQOqeUSNwXcneWYJHUREAIucJ5UZn).\n- [Modern API design with Golang, PostgreSQL and Docker](https:\u002F\u002Fbognov.tech\u002Fmodern-api-design-with-golang-postgresql-and-docker)\n\n## Ecosystem\n\n- Migrations by [vmihailenco](https:\u002F\u002Fgithub.com\u002Fgo-pg\u002Fmigrations) and\n  [robinjoseph08](https:\u002F\u002Fgithub.com\u002Frobinjoseph08\u002Fgo-pg-migrations).\n- [Genna - cli tool for generating go-pg models](https:\u002F\u002Fgithub.com\u002Fdizzyfool\u002Fgenna).\n- [bigint](https:\u002F\u002Fgithub.com\u002Fd-fal\u002Fbigint) - big.Int type for go-pg.\n- [urlstruct](https:\u002F\u002Fgithub.com\u002Fgo-pg\u002Furlstruct) to decode `url.Values` into structs.\n- [Sharding](https:\u002F\u002Fgithub.com\u002Fgo-pg\u002Fsharding).\n- [go-pg-monitor](https:\u002F\u002Fgithub.com\u002Fhypnoglow\u002Fgo-pg-monitor) - Prometheus metrics based on go-pg\n  client stats.\n\n## Features\n\n- Basic types: integers, floats, string, bool, time.Time, net.IP, net.IPNet.\n- sql.NullBool, sql.NullString, sql.NullInt64, sql.NullFloat64 and\n  [pg.NullTime](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#NullTime).\n- [sql.Scanner](http:\u002F\u002Fgolang.org\u002Fpkg\u002Fdatabase\u002Fsql\u002F#Scanner) and\n  [sql\u002Fdriver.Valuer](http:\u002F\u002Fgolang.org\u002Fpkg\u002Fdatabase\u002Fsql\u002Fdriver\u002F#Valuer) interfaces.\n- Structs, maps and arrays are marshalled as JSON by default.\n- PostgreSQL multidimensional Arrays using\n  [array tag](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB-Model-PostgresArrayStructTag)\n  and [Array wrapper](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-Array).\n- Hstore using\n  [hstore tag](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB-Model-HstoreStructTag)\n  and [Hstore wrapper](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-Hstore).\n- [Composite types](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB-Model-CompositeType).\n- All struct fields are nullable by default and zero values (empty string, 0, zero time, empty map\n  or slice, nil ptr) are marshalled as SQL `NULL`. `pg:\",notnull\"` is used to add SQL `NOT NULL`\n  constraint and `pg:\",use_zero\"` to allow Go zero values.\n- [Transactions](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB-Begin).\n- [Prepared statements](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB-Prepare).\n- [Notifications](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-Listener) using\n  `LISTEN` and `NOTIFY`.\n- [Copying data](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB-CopyFrom) using\n  `COPY FROM` and `COPY TO`.\n- [Timeouts](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#Options) and canceling queries using\n  context.Context.\n- Automatic connection pooling with\n  [circuit breaker](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FCircuit_breaker_design_pattern) support.\n- Queries retry on network errors.\n- Working with models using\n  [ORM](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model) and\n  [SQL](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Query).\n- Scanning variables using\n  [ORM](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-SelectSomeColumnsIntoVars)\n  and [SQL](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-Scan).\n- [SelectOrInsert](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-InsertSelectOrInsert)\n  using on-conflict.\n- [INSERT ... ON CONFLICT DO UPDATE](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-InsertOnConflictDoUpdate)\n  using ORM.\n- Bulk\u002Fbatch\n  [inserts](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-BulkInsert),\n  [updates](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-BulkUpdate), and\n  [deletes](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-BulkDelete).\n- Common table expressions using\n  [WITH](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-SelectWith) and\n  [WrapWith](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-SelectWrapWith).\n- [CountEstimate](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-CountEstimate)\n  using `EXPLAIN` to get\n  [estimated number of matching rows](https:\u002F\u002Fwiki.postgresql.org\u002Fwiki\u002FCount_estimate).\n- ORM supports\n  [has one](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-HasOne),\n  [belongs to](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-BelongsTo),\n  [has many](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-HasMany), and\n  [many to many](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-ManyToMany)\n  with composite\u002Fmulti-column primary keys.\n- [Soft deletes](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-SoftDelete).\n- [Creating tables from structs](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-CreateTable).\n- [ForEach](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-pg\u002Fpg\u002Fv10?tab=doc#example-DB.Model-ForEach) that calls\n  a function for each row returned by the query without loading all rows into the memory.\n\n## Installation\n\ngo-pg supports 2 last Go versions and requires a Go version with\n[modules](https:\u002F\u002Fgithub.com\u002Fgolang\u002Fgo\u002Fwiki\u002FModules) support. So make sure to initialize a Go\nmodule:\n\n```shell\ngo mod init github.com\u002Fmy\u002Frepo\n```\n\nAnd then install go-pg (note _v10_ in the import; omitting it is a popular mistake):\n\n```shell\ngo get github.com\u002Fgo-pg\u002Fpg\u002Fv10\n```\n\n## Quickstart\n\n```go\npackage pg_test\n\nimport (\n    \"fmt\"\n\n    \"github.com\u002Fgo-pg\u002Fpg\u002Fv10\"\n    \"github.com\u002Fgo-pg\u002Fpg\u002Fv10\u002Form\"\n)\n\ntype User struct {\n    Id     int64\n    Name   string\n    Emails []string\n}\n\nfunc (u User) String() string {\n    return fmt.Sprintf(\"User\u003C%d %s %v>\", u.Id, u.Name, u.Emails)\n}\n\ntype Story struct {\n    Id       int64\n    Title    string\n    AuthorId int64\n    Author   *User `pg:\"rel:has-one\"`\n}\n\nfunc (s Story) String() string {\n    return fmt.Sprintf(\"Story\u003C%d %s %s>\", s.Id, s.Title, s.Author)\n}\n\nfunc ExampleDB_Model() {\n    db := pg.Connect(&pg.Options{\n        User: \"postgres\",\n    })\n    defer db.Close()\n\n    err := createSchema(db)\n    if err != nil {\n        panic(err)\n    }\n\n    user1 := &User{\n        Name:   \"admin\",\n        Emails: []string{\"admin1@admin\", \"admin2@admin\"},\n    }\n    _, err = db.Model(user1).Insert()\n    if err != nil {\n        panic(err)\n    }\n\n    _, err = db.Model(&User{\n        Name:   \"root\",\n        Emails: []string{\"root1@root\", \"root2@root\"},\n    }).Insert()\n    if err != nil {\n        panic(err)\n    }\n\n    story1 := &Story{\n        Title:    \"Cool story\",\n        AuthorId: user1.Id,\n    }\n    _, err = db.Model(story1).Insert()\n    if err != nil {\n        panic(err)\n    }\n\n    \u002F\u002F Select user by primary key.\n    user := &User{Id: user1.Id}\n    err = db.Model(user).WherePK().Select()\n    if err != nil {\n        panic(err)\n    }\n\n    \u002F\u002F Select all users.\n    var users []User\n    err = db.Model(&users).Select()\n    if err != nil {\n        panic(err)\n    }\n\n    \u002F\u002F Select story and associated author in one query.\n    story := new(Story)\n    err = db.Model(story).\n        Relation(\"Author\").\n        Where(\"story.id = ?\", story1.Id).\n        Select()\n    if err != nil {\n        panic(err)\n    }\n\n    fmt.Println(user)\n    fmt.Println(users)\n    fmt.Println(story)\n    \u002F\u002F Output: User\u003C1 admin [admin1@admin admin2@admin]>\n    \u002F\u002F [User\u003C1 admin [admin1@admin admin2@admin]> User\u003C2 root [root1@root root2@root]>]\n    \u002F\u002F Story\u003C1 Cool story User\u003C1 admin [admin1@admin admin2@admin]>>\n}\n\n\u002F\u002F createSchema creates database schema for User and Story models.\nfunc createSchema(db *pg.DB) error {\n    models := []interface{}{\n        (*User)(nil),\n        (*Story)(nil),\n    }\n\n    for _, model := range models {\n        err := db.Model(model).CreateTable(&orm.CreateTableOptions{\n            Temp: true,\n        })\n        if err != nil {\n            return err\n        }\n    }\n    return nil\n}\n```\n\n## See also\n\n- [Golang PostgreSQL](https:\u002F\u002Fbun.uptrace.dev\u002Fpostgres\u002F)\n- [Golang HTTP router](https:\u002F\u002Fgithub.com\u002Fuptrace\u002Fbunrouter)\n- [Golang ClickHouse ORM](https:\u002F\u002Fgithub.com\u002Fuptrace\u002Fgo-clickhouse)\n- [Golang msgpack](https:\u002F\u002Fgithub.com\u002Fvmihailenco\u002Fmsgpack)\n- [Distributed tracing tools](https:\u002F\u002Fget.uptrace.dev\u002Fcompare\u002Fdistributed-tracing-tools.html)\n","go-pg\u002Fpg 是一个专注于PostgreSQL特性和性能的Golang ORM库。它支持基本类型如整数、浮点数、字符串等，并且能够处理更复杂的数据结构，比如多维数组和Hstore数据类型。此外，该项目还提供了丰富的SQL扫描器接口与驱动值接口的支持，使得Go语言中的结构体、映射和数组可以默认被序列化为JSON格式存储。go-pg\u002Fpg特别适用于需要高性能数据库操作以及利用PostgreSQL高级功能（如JSONB字段）的应用场景中。尽管目前该项目处于维护模式，但其稳定性和功能仍然使其成为构建依赖于PostgreSQL数据库服务的理想选择之一。",2,"2026-06-11 03:28:22","top_topic"]