Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Superset | 54,394 | 16 | 10 hours ago | 6 | April 18, 2023 | 1,523 | apache-2.0 | TypeScript | ||
Apache Superset is a Data Visualization and Data Exploration Platform | ||||||||||
Tidb | 34,927 | 68 | 137 | 9 hours ago | 1,289 | April 07, 2022 | 4,370 | apache-2.0 | Go | |
TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://tidbcloud.com/free-trial | ||||||||||
Metabase | 34,416 | 9 hours ago | 1 | June 08, 2022 | 3,255 | other | Clojure | |||
The simplest, fastest way to get business intelligence and analytics to everyone in your company :yum: | ||||||||||
Dbeaver | 33,961 | 9 hours ago | 1,803 | apache-2.0 | Java | |||||
Free universal database tool and SQL client | ||||||||||
Sqlmap | 28,261 | 5 days ago | 1 | February 27, 2018 | 57 | other | Python | |||
Automatic SQL injection and database takeover tool | ||||||||||
Cockroach | 27,882 | 50 | 24 | 9 hours ago | 249 | August 06, 2021 | 5,634 | other | Go | |
CockroachDB - the open source, cloud-native distributed SQL database. | ||||||||||
Directus | 23,287 | 185 | 9 hours ago | 86 | July 25, 2023 | 299 | other | TypeScript | ||
The Modern Data Stack 🐰 — Directus is an instant REST+GraphQL API and intuitive no-code data collaboration app for any SQL database. | ||||||||||
Surrealdb | 22,680 | 16 | 9 hours ago | 10 | April 02, 2023 | 341 | other | Rust | ||
A scalable, distributed, collaborative, document-graph database, for the realtime web | ||||||||||
Tdengine | 21,776 | 2 | 9 hours ago | 12 | April 14, 2022 | 1,197 | agpl-3.0 | C | ||
TDengine is an open source, high-performance, cloud native time-series database optimized for Internet of Things (IoT), Connected Cars, Industrial IoT and DevOps. | ||||||||||
Postgrest | 21,164 | 4 | 9 hours ago | 37 | July 12, 2022 | 215 | mit | Haskell | ||
REST API for any Postgres database |
A minimalistic relational database library for Go.
Table of Contents
$ go get github.com/azer/crud/v2
import (
"github.com/azer/crud/v2"
_ "github.com/go-sql-driver/mysql"
)
var DB *crud.DB
func init () {
var err error
DB, err = crud.Connect("mysql", os.Getenv("DATABASE_URL"))
err = DB.Ping()
}
type User struct {
Id int `sql:"auto-increment primary-key"`
FirstName string
LastName string
ProfileId int
}
type Profile struct {
Id int `sql:"auto-increment primary-key"`
Bio string `sql:"text"`
}
CRUD will automatically convert column names from "FirstName" (CamelCase) to "first_name" (snake_case) for you. You can still choose custom names though;
type Post struct {
Slug string `sql:"name=slug_id varchar(255) primary-key required"`
}
If no primary key is specified, CRUD will look for a field named "Id" with int type, and set it as auto-incrementing primary-key field.
CreateTables
takes list of structs and makes sure they exist in the database.
err := DB.CreateTables(User{}, Profile{})
err := DB.DropTables(User{}, Profile{})
Shortcut for dropping and creating tables.
err := DB.ResetTables(User{}, Profile{})
CRUD tries to be smart about figuring out the best SQL options for your structs, and lets you choose manually, too. For example;
type Tweet struct {
Text string `sql:"varchar(140) required name=tweet"`
}
Above example sets the type of the Text
column as varchar(140)
, makes it required (NOT NULL
) and changes the column name as tweet
.
Here is the list of the options that you can pass;
int
, bigint
, varchar
, text
, date
, time
, timestamp
auto-increment
/ autoincrement
/ auto_increment
primary-key
/ primarykey
/ primary_key
required
default='?'
name=?
table-name=?
If you'd like a struct field to be ignored by CRUD, choose -
as options:
type Foo struct {
IgnoreMe string `sql:"-"`
}
Simply pass a struct. It can be pointer or not.
user := &User{1, "Foo", "Bar", 1}
err := DB.Create(user)
Create a row, and read it back from the DB. The values of the struct you passed get resetted to whatever the corresponding DB row has. In the other words, CreateAndRead
creates, and reads. So you got fields generated by the DB scanned to your struct, like ID.
Make sure passing a pointer.
user := User{
FirstName:"Foo"
}
err := DB.CreateAndRead(&user)
user.Id
// => 123
You can read single/multiple rows, or custom values, with the Read
method.
Pass your struct's pointer, and a query;
user := &User{}
err := DB.Read(user, "SELECT * FROM users WHERE id = ?", 1)
// => SELECT * FROM users WHERE id = 1
fmt.Println(user.Name)
// => Foo
users := []*User{}
err := DB.Read(&users, "SELECT * FROM users")
// => SELECT * FROM users
fmt.Println(len(users))
// => 10
names := []string{}
err := DB.Read(&names, "SELECT name FROM users")
name := ""
err := DB.Read(&name, "SELECT name FROM users WHERE id=1")
totalUsers := 0
err := DB.Read(&totalUsers, "SELECT COUNT(id) FROM users"
Updates matching row in database, returns sql.ErrNoRows
nothing matched.
user := &User{}
err := DB.Read(user, "SELECT * FROM users WHERE id = ?", 1)
user.Name = "Yolo"
err := DB.Update(user)
Deletes matching row in database, returns sql.ErrNoRows
nothing matched.
err := DB.Delete(&User{
Id: 1
})
Use WithContext
method to get a DB client with context. Here is an example;
db := DB.WithContext(context.Background())
Use Begin
method of a crud.DB
instance to create a new transaction. Each transaction will provide you following methods;
tx, err := DB.Begin(context.Background())
err := tx.Create(&User{
Name: "yolo"
})
err := tx.Delete(&User{
Id: 123
})
err := tx.Commit()
CRUD generates an ID for each transaction, and uses that for logging queries and the state of the transactions. You can override transaction IDs in some use cases such as having same IDs and ID field keys with your Rest framework generating request IDs;
tx.Id = requestId
tx.IdKey = "requestId"
If you want to see crud's internal logs, specify crud
in the LOG
environment variable when you run your app. For example;
$ LOG=crud go run myapp.go
result, err := DB.Query("DROP DATABASE yolo") // or .Exec
DATABASE_URL="?" go test ./...