A simple wrapper around sql.DB to help with structs. Not quite an ORM.

Related tags

ORM go-modeldb
Overview

go-modeldb

A simple wrapper around sql.DB to help with structs. Not quite an ORM.

Philosophy: Don't make an ORM

Example:

// Setup
require "modeldb"
db := ...
modeldb.SetDB(db)


// Declaring a model
type User struct {
    Id       string `json:"id"      db:"id,autoinc"`
    Email    string `json:"email"   db:"email,null"`
    Scrypt   []byte `json:"-"       db:"scrypt"`
    Salt     []byte `json:"-"       db:"salt"`
}   
var UserModel = db.GetModelInfo(new(User))


// Inserting a model
user := &User{Email:email, Scrypt:scrypt, Salt:salt}
_, err = modeldb.Exec(
    `INSERT INTO user (`+UserModel.InsertFields+`)
     VALUES (`+UserModel.Placeholders+`)`,
    user,
) 


// Querying a model
var user User
err := modeldb.QueryRow(
    `SELECT `+UserModel.QueryFields+`
     FROM user WHERE email=?`,
    email,
).Scan(&user)


// Querying many rows
rows, err := modeldb.QueryAll(User{},
    `SELECT `+UserModel.QueryFields+`
     FROM user WHERE id < 100`)     
)   
if err != nil { panic(err) }
users := rows.([]*User)


// Auto-retry transaction blocks
err := db.DoBeginSerializable(func(tx *db.ModelTx) {
    _, err := tx.Exec(...)
    if err != nil {
        panic(err)
    }
    ...
})

Also supports MySQL with some included helpers.

Alternatives

https://github.com/jmoiron/sqlx

Owner
Jae Kwon
Tendermint, Cosmos, now Gno
Jae Kwon
Using-orm-with-db - Trying to use ORM to work with PostgreSQL

Using ORM with db This repo contains the training (rough) code, and possibly not

Pavel V 2 Jan 6, 2022
Simple and performant ORM for sql.DB

Simple and performant ORM for sql.DB Main features are: Works with PostgreSQL, MySQL, SQLite. Selecting into a map, struct, slice of maps/structs/vars

Uptrace 894 May 14, 2022
beedb is a go ORM,support database/sql interface,pq/mysql/sqlite

Beedb ❗ IMPORTANT: Beedb is being deprecated in favor of Beego.orm ❗ Beedb is an ORM for Go. It lets you map Go structs to tables in a database. It's

astaxie 709 Mar 8, 2022
100% type-safe ORM for Go (Golang) with code generation and MySQL, PostgreSQL, Sqlite3, SQL Server support. GORM under the hood.

go-queryset 100% type-safe ORM for Go (Golang) with code generation and MySQL, PostgreSQL, Sqlite3, SQL Server support. GORM under the hood. Contents

Denis Isaev 660 May 9, 2022
SQL mapper ORM framework for Golang

SQL mapper ORM framework for Golang English 中文 Please read the documentation website carefully when using the tutorial. DOC Powerful Features High Per

null 0 Dec 8, 2021
Mybatis for golang - SQL mapper ORM framework

SQL mapper ORM framework for Golang English 中文 Please read the documentation website carefully when using the tutorial. DOC Powerful Features High Per

Tim 2 Mar 20, 2022
Simple Go ORM for Google/Firebase Cloud Firestore

go-firestorm Go ORM (Object-relational mapping) for Google Cloud Firestore. Goals Easy to use Non intrusive Non exclusive Fast Features Basic CRUD ope

Jens Kjær Schødt 28 May 8, 2022
Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm

xorm HAS BEEN MOVED TO https://gitea.com/xorm/xorm . THIS REPOSITORY WILL NOT BE UPDATED ANY MORE. 中文 Xorm is a simple and powerful ORM for Go. Featur

null 6.5k May 11, 2022
Go tool for generating sql scanners, sql statements and other helper functions

sqlgen generates SQL statements and database helper functions from your Go structs. It can be used in place of a simple ORM or hand-written SQL. See t

drone.io 182 Jan 3, 2022
Simple project in Go to play around with some CRUD operations using a PostgreSQL database and pgx

Record Store November 2021 I started learning Go a few weeks ago and this is my first proper project using Go. I wanted to use it to get to grips with

Katie Hawcutt 0 Nov 26, 2021
ORM-ish library for Go

We've moved! gorp is now officially maintained at: https://github.com/go-gorp/gorp This fork was created when the project was moved, and is provided f

James Cooper 53 Nov 22, 2021
Database agnostic ORM for Go

If you are looking for something more lightweight and flexible, have a look at jet For questions, suggestions and general topics visit the group. Inde

Erik Aigner 693 May 6, 2022
QBS stands for Query By Struct. A Go ORM.

Qbs Qbs stands for Query By Struct. A Go ORM. 中文版 README ChangeLog 2013.03.14: index name has changed to {table name}_{column name}. For existing appl

Evan Zhou 548 May 1, 2022
Generate a Go ORM tailored to your database schema.

SQLBoiler is a tool to generate a Go ORM tailored to your database schema. It is a "database-first" ORM as opposed to "code-first" (like gorm/gorp). T

Volatile Technologies Inc. 4.9k May 12, 2022
A better ORM for Go, based on non-empty interfaces and code generation.

reform A better ORM for Go and database/sql. It uses non-empty interfaces, code generation (go generate), and initialization-time reflection as oppose

null 1.3k May 14, 2022
A better ORM for Go, based on non-empty interfaces and code generation.

A better ORM for Go and database/sql. It uses non-empty interfaces, code generation (go generate), and initialization-time reflection as opposed to interface{}, type system sidestepping, and runtime reflection. It will be kept simple.

null 1.2k May 12, 2022
An orm library support nGQL for Golang

norm An ORM library support nGQL for Golang. Overview Build insert nGQL by struct / map (Support vertex, edge). Parse Nebula execute result to struct

Zhihu 65 May 9, 2022
golang orm

korm golang orm, 一个简单易用的orm, 支持嵌套事务 安装 go get github.com/wdaglb/korm go get github.com/go-sql-driver/mysql 支持数据库 mysql https://github.com/go-sql-driv

null 6 Oct 11, 2021
Golang ORM with focus on PostgreSQL features and performance

go-pg is in a maintenance mode and only critical issues are addressed. New development happens in Bun repo which offers similar functionality but works with PostgreSQL, MySQL, and SQLite.

null 5.1k May 10, 2022