/ mozey.co / blog

golang orm comparison

December 1, 2015

🔗 gorm

TODO…

🔗 sqlx

Illustrated guide to SQLX

🔗 Main types

sqlx is intended to have the same feel as database/sql, with 4 main handle types similar to sql.*

🔗 sqlx.DB = database

Not a connection, but an abstraction representing a Database.

Maintains a connection pool internally, and will attempt to connect when a connection is first needed.

var db *sqlx.DB
var err error

exactly the same as the built-in

db = sqlx.Open("sqlite3", ":memory:")

from a pre-existing sql.DB; note the required driverName

db = sqlx.NewDB(sql.Open("sqlite3", ":memory:"), "sqlite3")

force a connection and test that it worked

err = db.Ping()

open and connect at the same time:

db, err = sqlx.Connect("sqlite3", ":memory:")

open and connect at the same time, panicking on error

db = sqlx.MustConnect("sqlite3", ":memory:")

🔗 sqlx.Tx = transaction

🔗 sqlx.Stmt = prepared statement

🔗 sqlx.NamedStmt = prepared statement with support for named parameters

🔗 Cursor types

🔗 sqlx.Rows = returned from Queryx

🔗 sqlx.Row = returned from QueryRowx

🔗 Querying

🔗 Transactions

🔗 Prepared Statements

🔗 Advanced Scanning

🔗 Custom Types

🔗 More Drivers

🔗 MySQL