Golang Client Code-Generator for SQL Database (Postgres, SQLite, ...)
MIT License
MangoSQL is a fresh and juicy SQL code generator for Golang.
MangoSQL is the perfect choice if you don't want an heavy ORM, but don't want to write all the SQL queries by hand like a caveman either. Originally inspired by SQLC, but pushes the idea farther by natively supporting batching, relations and dynamic queries.
Links: ð Getting Started | ðŧ API Reference | ð Benchmark
sql.go
in an instantSo let's see what it means in reality. For the following:
CREATE TABLE users (
id UUID PRIMARY KEY,
email VARCHAR(64) NOT NULL,
name VARCHAR(64) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
deleted_at TIMESTAMP DEFAULT NULL
);
Execute the following command to automatically generate a database/client.go
mangosql --output=database schema.sql
This is all you need to do, now the client can be used in your code
db := database.New(dbConnection)
// Handle crud operation
user, err := db.User.Insert(database.UserCreate{
Name: "user1",
Email: "[email protected]"
})
// Typed dynamic clauses (filters, pagination, ...) with typed helpers
users, err := db.User.FindMany(
db.User.Query.Name.Like("%user%"),
db.User.Query.Limit(20)
)
// Raw dynamic clauses
users, err := db.User.FindMany(func(query SelectBuilder) SelectBuilder {
return query.Where("name ILIKE $1 OR name ILIKE $2", "%user1%", "%user2%")
})
// To know more about MangoSQL APIs ... RTFM ^^