Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Knex | 17,597 | 18,096 | 2,788 | a day ago | 248 | August 31, 2022 | 830 | mit | JavaScript | |
A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use. | ||||||||||
Objection.js | 7,005 | 707 | 338 | 4 days ago | 195 | December 30, 2021 | 106 | mit | JavaScript | |
An SQL-friendly ORM for Node.js | ||||||||||
Querybuilder | 2,661 | 8 | 99 | 2 months ago | 56 | September 19, 2022 | 119 | mit | C# | |
SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql, PostgreSql, Oracle, Sqlite and Firebird | ||||||||||
Pypika | 2,000 | 19 | 45 | a month ago | 213 | March 15, 2022 | 167 | apache-2.0 | Python | |
PyPika is a python SQL query builder that exposes the full richness of the SQL language using a syntax that reflects the resulting query. PyPika excels at all sorts of SQL queries but is especially useful for data analysis. | ||||||||||
Goqu | 1,846 | 46 | 3 months ago | 25 | October 16, 2021 | 104 | mit | Go | ||
SQL builder and query library for golang | ||||||||||
React Awesome Query Builder | 1,544 | 5 | 8 | 20 days ago | 144 | March 15, 2022 | 116 | mit | JavaScript | |
User-friendly query builder for React | ||||||||||
Squel | 1,520 | 423 | 154 | 3 years ago | 79 | June 18, 2019 | 121 | mit | CoffeeScript | |
:office: SQL query string builder for Javascript | ||||||||||
Gendry | 1,485 | 18 | a month ago | 16 | March 23, 2021 | 18 | apache-2.0 | Go | ||
a golang library for sql builder | ||||||||||
Jet | 1,272 | 2 | 11 days ago | 29 | May 17, 2022 | 21 | apache-2.0 | Go | ||
Type safe SQL builder with code generation and automatic query result data mapping | ||||||||||
Go Sqlbuilder | 994 | 3 | 30 | 15 days ago | 27 | June 25, 2022 | 8 | mit | Go | |
A flexible and powerful SQL string builder library plus a zero-config ORM. |
Gatsby Query provides a general query object to build SQL for selecting, updating, deleting, inserting records.
Currently it supports 4 mode (CRUD) to build SQL.
To Build Select Query:
import "gatsby"
staffs := gatsby.NewQuery("staffs")
staffs.Select("id", "name")
staffs.WhereFromMap( gatsby.ArgMap{
"name": "John"
})
sql := staffs.String()
args := staffs.Args()
To Build Insert Query:
import "gatsby"
query := gatsby.NewQuery("staffs")
query.Insert(map[string]interface{} {
"name": "John",
})
sql := query.String()
To Build Update Query:
query := gatsby.NewQuery("staffs")
query.Update(map[string]interface{} {
"name": "John",
})
query.WhereFromMap(map[string]interface{} {
"id": 3,
})
sql := query.String()
More flexible SQL Builder by fragments.
You can append query fragments then combine them into one SQL string by joining, and you can use the generated SQL in anywhere you want to combine with your own SQL statements.
SQLFragments filters these question marks into placeholders with number format, for example, the first ?
will be $1
and the second ?
will be $2
.
import "gatsby"
frag := gatsby.NewFragment()
frag.AppendQuery("name = ?", "John")
frag.AppendQuery("phone = ?", "John")
sql := frag.Join("OR") // generates name = $1 AND phone = $2
args := frag.Args()
The BaseRecord provides a general CRUD operations on a struct type.
To define your model with Gatsby BaseRecord:
package app
import "github.com/c9s/gatsby"
type Staff struct {
Id int64 `json:"id" field:"id,primary,serial"`
Name string `json:"name"`
Gender string `json:"gender"`
Phone string `json:"phone"`
CellPhone string `json:"cell_phone"`
gatsby.BaseRecord
}
Then you can do CRUD operations on the struct object:
import "github.com/c9s/gatsby"
import _ "github.com/mattn/go-sqlite3"
import "database/sql"
db, err := sql.Open("sqlite3", "./foo.db")
gatsby.SetupConnection(db, gatsby.DriverSqlite)
staff := gatsby.NewRecord(&Staff{}).(*Staff)
res := staff.Load(10) // load the record where primary key = 10
if res.Error != nil {
// handle error here
}
if res.IsEmpty {
// handle empty record here
}
staff.Name = "John"
res := staff.Update()
res := staff.Delete() // delete the record where primary key = 10
res := staff.Create() // create another record
if res.Error != nil {
}