SkillAgentSearch skills...

Goql

Super simple SQL query builder

Install / Use

/learn @rgamba/Goql
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

goql

Build Status

goql is a super fast and easy to use query builder and database table to struct modeling convention. It is like an ORM but it just gets out of your way and let's you keep control of your queries.

For the following examples, let's assume you have the following table user:

id | username | password -- | -- | -- 1 | ricardo | secret123 2 | admin | ultrasecret

Mapping a table to a struct

type User struct {
	ID       int64  `db:"id" pk:"true"`
	Username string `db:"username"`
	Password string `db:"password"`
}

Select queries

query := goql.QueryBuilder{}
query.Select("id, username, password").From("user").Where("id = $?", 1).QueryAndScan(db, &user)
fmt.Println(user.username) // -> "ricardo"

Or even better...

myuser := User{}
query := goql.QueryBuilder{}
query.Select(myser).Where("id = $?", 1).QueryAndScan(db, &user)
fmt.Println(user.username) // -> "ricardo"

Insert or update

newUser := User{ID: 3, Name: "John", Password: "123"}
Insert(db, "user", newUser)

newUser.Name = "Bob"
Update(db, "user", newUser)

Note db in both cases must be either of type *sql.DB or *sql.Tx

Related Skills

View on GitHub
GitHub Stars17
CategoryData
Updated2y ago
Forks1

Languages

Go

Security Score

65/100

Audited on Dec 17, 2023

No findings