go-lightning
A lightweight, high-performance database library for Go that prioritizes simplicity and speed.
Why go-lightning?
Easy to Use
Simple API with minimal learning curve. Define a struct, register it, and start querying. No complex configurations or setup required.
Cached Queries
INSERT and UPDATE statements are pre-computed at registration time. Zero runtime overhead for query generation—everything is ready when you need it.
SQL-First
Write your own SQL queries. No magic query builders or DSLs to learn. Full control over your database operations with raw SQL.
Insert/Update Out of the Box
Auto-generated INSERT and UPDATE statements from your struct definition. No boilerplate code for basic CRUD operations.
Lightweight
Minimal dependencies, small footprint. Only imports database/sql and github.com/google/uuid. No heavy ORM frameworks.
No Code Generation
Unlike sqlc or ent, there's no build step required. No generated files to maintain. Just import and use.
Quick Example
package main
import (
"database/sql"
"github.com/tracewayapp/go-lightning/lit"
_ "github.com/lib/pq"
)
// Define your model
type User struct {
Id int
FirstName string
LastName string
Email string
}
func main() {
// Register the model (happens once at startup)
lit.RegisterModel[User](lit.PostgreSQL)
// Connect to database
db, _ := sql.Open("postgres", "postgres://localhost/mydb?sslmode=disable")
// Create
user := User{FirstName: "John", LastName: "Doe", Email: "john@example.com"}
id, _ := lit.Insert(db, &user)
// Read
users, _ := lit.Select[User](db, "SELECT id, first_name, last_name, email FROM users")
// Read single
user, _ := lit.SelectSingle[User](db, "SELECT id, first_name, last_name, email FROM users WHERE id = $1", id)
// Update
user.FirstName = "Jane"
lit.Update(db, &user, "id = $1", user.Id)
// Delete
lit.Delete(db, "DELETE FROM users WHERE id = $1", id)
}Get Started
Ready to use go-lightning? Follow the installation guide or jump straight to the quick start.