Product Promotion
0x5a.live
for different kinds of informations and explorations.
GitHub - lqs/sqlingo: 💥 A lightweight DSL & ORM which helps you to write SQL in Go.
💥 A lightweight DSL & ORM which helps you to write SQL in Go. - lqs/sqlingo
Visit SiteGitHub - lqs/sqlingo: 💥 A lightweight DSL & ORM which helps you to write SQL in Go.
💥 A lightweight DSL & ORM which helps you to write SQL in Go. - lqs/sqlingo
Powered by 0x5a.live 💗
sqlingo is a SQL DSL (a.k.a. SQL Builder or ORM) library in Go. It generates code from the database and lets you write SQL queries in an elegant way.
Features
- Auto-generating DSL objects and model structs from the database so you don't need to manually keep things in sync
- SQL DML (SELECT / INSERT / UPDATE / DELETE) with some advanced SQL query syntaxes
- Many common errors could be detected at compile time
- Your can use the features in your editor / IDE, such as autocompleting the fields and queries, or finding the usage of a field or a table
- Context support
- Transaction support
- Interceptor support
- Golang time.Time is supported now, but you can still use the string type by adding
-timeAsString
when generating the model
Database Support Status
Database | Status |
---|---|
MySQL | stable |
PostgreSQL | experimental |
SQLite | experimental |
Tutorial
Install and use sqlingo code generator
The first step is to generate code from the database. In order to generate code, sqlingo requires your tables are already created in the database.
$ go install github.com/lqs/sqlingo/sqlingo-gen-mysql@latest
$ mkdir -p generated/sqlingo
$ sqlingo-gen-mysql root:123456@/database_name >generated/sqlingo/database_name.dsl.go
Write your application
Here's a demonstration of some simple & advanced usage of sqlingo.
package main
import (
"github.com/lqs/sqlingo"
. "./generated/sqlingo"
)
func main() {
db, err := sqlingo.Open("mysql", "root:123456@/database_name")
if err != nil {
panic(err)
}
// a simple query
var customers []*CustomerModel
db.SelectFrom(Customer).
Where(Customer.Id.In(1, 2)).
OrderBy(Customer.Name.Desc()).
FetchAll(&customers)
// query from multiple tables
var customerId int64
var orderId int64
err = db.Select(Customer.Id, Order.Id).
From(Customer, Order).
Where(Customer.Id.Equals(Order.CustomerId), Order.Id.Equals(1)).
FetchFirst(&customerId, &orderId)
// subquery and count
count, err := db.SelectFrom(Order)
Where(Order.CustomerId.In(db.Select(Customer.Id).
From(Customer).
Where(Customer.Name.Equals("Customer One")))).
Count()
// group-by with auto conversion to map
var customerIdToOrderCount map[int64]int64
err = db.Select(Order.CustomerId, f.Count(1)).
From(Order).
GroupBy(Order.CustomerId).
FetchAll(&customerIdToOrderCount)
if err != nil {
println(err)
}
// insert some rows
customer1 := &CustomerModel{name: "Customer One"}
customer2 := &CustomerModel{name: "Customer Two"}
_, err = db.InsertInto(Customer).
Models(customer1, customer2).
Execute()
// insert with on-duplicate-key-update
_, err = db.InsertInto(Customer).
Fields(Customer.Id, Customer.Name).
Values(42, "Universe").
OnDuplicateKeyUpdate().
Set(Customer.Name, Customer.Name.Concat(" 2")).
Execute()
}
GoLang Resources
are all listed below.
GitHub - GuilhermeCaruso/anko: :crystal_ball: Simple application watcher
resource
~/github.com
resource
GitHub - jidicula/go-fuzz-action: GitHub Action for Go 1.18 fuzz testing
resource
~/github.com
resource
GitHub - tucnak/climax: Climax is an alternative CLI with the human face
resource
~/github.com
resource
GitHub - lawrencewoodman/roveralls: A Go recursive coverage testing tool
resource
~/github.com
resource
GitHub - nakagami/firebirdsql: Firebird RDBMS sql driver for Go (golang)
resource
~/github.com
resource
GitHub - liweiyi88/onedump: Effortlessly database dump with one command.
resource
~/github.com
resource
GitHub - beefsack/go-astar: Go implementation of the A* search algorithm
resource
~/github.com
resource
GitHub - lxn/walk: A Windows GUI toolkit for the Go Programming Language
resource
~/github.com
resource
GitHub - mongodb/mongo-go-driver: The Official Golang driver for MongoDB
resource
~/github.com
resource
GitHub - mozillazg/go-unidecode: ASCII transliterations of Unicode text.
resource
~/github.com
resource
GitHub - bolknote/go-gd: Go bingings for GD (http://www.boutell.com/gd/)
resource
~/github.com
resource
GitHub - mosajjal/dnsmonster: Passive DNS Capture and Monitoring Toolkit
resource
~/github.com
resource
GitHub - haxpax/gosms: :mailbox_closed: Your own local SMS gateway in Go
resource
~/github.com
resource
GitHub - wajox/gobase: This is a simple skeleton for golang applications
resource
~/github.com
resource
GitHub - VividCortex/gohistogram: Streaming approximate histograms in Go
resource
~/github.com
resource
GitHub - malaschitz/randomForest: Random Forest implementation in golang
resource
~/github.com
resource
GitHub - google/gopacket: Provides packet processing capabilities for Go
resource
~/github.com
resource
GitHub - khezen/evoli: Genetic Algorithm and Particle Swarm Optimization
resource
~/github.com
resource
GitHub - didip/tollbooth: Simple middleware to rate-limit HTTP requests.
resource
~/github.com
resource
GitHub - mustafaakin/gongular: A different approach to Go web frameworks
resource
~/github.com
resource
GitHub - songgao/colorgo: Colorize (highlight) `go build` command output
resource
~/github.com
resource
Made with ❤️
to provide different kinds of informations and resources.