All Projects → auula → gsql

auula / gsql

Licence: MIT License
GSQL is a structured query language code builder for golang.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to gsql

gogen
Command-line tool to generate GO applications and libraries
Stars: ✭ 17 (-83.96%)
Mutual labels:  builder, code
lowcode
React Lowcode - prototype, develop and maintain internal apps easier
Stars: ✭ 32 (-69.81%)
Mutual labels:  builder, code
DPB
Dynamic Project Builder
Stars: ✭ 22 (-79.25%)
Mutual labels:  builder, code
Updated Carbanak Source With Plugins
https://twitter.com/itsreallynick/status/1120410950430089224
Stars: ✭ 303 (+185.85%)
Mutual labels:  builder, code
sphinx-markdown-builder
sphinx builder that outputs markdown files.
Stars: ✭ 135 (+27.36%)
Mutual labels:  builder, code
AppRopio.Mobile
AppRopio - mobile apps builder for iOS/Android based on Xamarin
Stars: ✭ 16 (-84.91%)
Mutual labels:  builder
find-sec-bugs-demos
Repository to showcase various configuration recipes with various technologies
Stars: ✭ 33 (-68.87%)
Mutual labels:  code
micro-code-analyser
A tiny Node.js microservice to detect the language of a code snippet
Stars: ✭ 21 (-80.19%)
Mutual labels:  code
StablexUI-Designer
Graphical designer (gui-builder) for library StablexUI
Stars: ✭ 14 (-86.79%)
Mutual labels:  builder
cosy
阿里云智能编码插件(Alibaba Cloud AI Coding Assistant)是一款AI编程助手,它提供代码智能补全和IDE内的代码示例搜索能力,帮助你更快更高效地写出高质量代码。
Stars: ✭ 211 (+99.06%)
Mutual labels:  code
plasmic
Visual page builder and web design tool for any website or web app tech stack
Stars: ✭ 1,475 (+1291.51%)
Mutual labels:  builder
schema
TYPO3 extension providing an API and view helpers for schema.org markup
Stars: ✭ 19 (-82.08%)
Mutual labels:  structured-data
php-schema.org-mapping
A fluent interface to create mappings using Schema.org for Microdata and JSON-LD.
Stars: ✭ 31 (-70.75%)
Mutual labels:  builder
code-examples
Short code snippets written by our open source community!
Stars: ✭ 60 (-43.4%)
Mutual labels:  code
go-captcha
Go Captcha is a behavioral captcha, which implements the generation of random verification text and the verification of click position information.
Stars: ✭ 86 (-18.87%)
Mutual labels:  code
Domainker
BugBounty Tool
Stars: ✭ 40 (-62.26%)
Mutual labels:  code
Discord-Nitro-BruteForce
simple discord nitro code generator and checker written in c#
Stars: ✭ 26 (-75.47%)
Mutual labels:  code
open-gsa-redesign
A fresh start for open.gsa.gov.
Stars: ✭ 27 (-74.53%)
Mutual labels:  code
buildit.nvim
A better async project builder for Neovim
Stars: ✭ 18 (-83.02%)
Mutual labels:  builder
dqlx
A DGraph Query Builder
Stars: ✭ 41 (-61.32%)
Mutual labels:  builder

GSQL

GSQL is a structured query language code builder for golang.

Genreate SQL

  1. Model Structured
type UserInfo struct {
	Id   int    `db:"id" pk:"id"`
	Name string `db:"name"`
	Age  int    `db:"age"`
}

db identifies the database table field,pk is the primary key.

  1. Simple query
sql1 := gsql.Select().From(UserInfo{})

// SELECT id, name, age FROM UserInfo
t.Log(sql1)
  1. Alias and pass primary key
sql2 := gsql.SelectAs([]string{"name", gsql.As("age", "年龄"), "id"}).From(UserInfo{}).ById(2)

// SELECT name, age AS '年龄' FROM UserInfo WHERE  id = 2
t.Log(sql2)


sql3 := gsql.SelectAs(gsql.Alias(UserInfo{}, map[string]string{
    "name": "名字",
})).From(UserInfo{}).ById(1)

// SELECT id, name AS '名字', age FROM UserInfo WHERE  id = 1
t.Log(sql3)

SelectAs if the parameter is sliceid = pk:"id" The last parameter must be the primary key field of the table.

  1. Query a set of data to provide the primary key
sql := gsql.Select().From(UserInfo{}).ByIds(1, 2, 3)

// SELECT id, name, age FROM UserInfo WHERE id IN (1, 2, 3)
t.Log(sql)
  1. Query by In
sql := gsql.Select().From(UserInfo{}).In("age", 21, 19, 28)

// SELECT id, name, age FROM UserInfo WHERE age IN (21, 19, 28)
t.Log(sql)
  1. Query a piece of data
func TestSelectOne(t *testing.T) {
	
	// SELECT id, name, age FROM UserInfo LIMIT 1
	_, sql := gsql.Select().From(UserInfo{}).One()
	t.Log(sql)

	// SELECT id, name, age FROM UserInfo WHERE age > 10 LIMIT 1
	err, sql2 := gsql.Select().From(UserInfo{}).Where("age > ?", 10).One()

	if err == nil {
		t.Log(sql2)
	}
}
  1. Sort or filter
func TestSelectLimit(t *testing.T) {

	// SELECT id, name, age FROM UserInfo WHERE age > 10 LIMIT 3 OFFSET 1
	sql2 := gsql.Select().From(UserInfo{}).Where("age > ?", 10).Limit(true, 1, 3)

	t.Log(sql2)

}

func TestSelectOrder(t *testing.T) {

	// SELECT id, name, age FROM UserInfo WHERE age > 10 ORDER BY id ASC LIMIT 3 OFFSET 1
	sql2 := gsql.Select().From(UserInfo{}).Where("age > ?", 10).Order([]gsql.Rows{
		{"id", "ASC"},
	}).Limit(true, 1, 3)

	t.Log(sql2)

}
  1. Insert Data to table
func TestInsert(t *testing.T) {
	// INSERT INTO UserInfo (id, name, age) VALUES (1001, 'Tom', 21)
	sql := gsql.Insert(UserInfo{}, nil).Values(1001, "Tom", 21)
	t.Log(sql)
}

func TestInsertFilter(t *testing.T) {
	// INSERT INTO UserInfo (name, age) VALUES ('Tom', 21)
	err, sql := gsql.Insert(UserInfo{}, []string{"id"}).Values("Tom", 21).Build()
	if err != nil {
		t.Log(err)
	}
	t.Log(sql)
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].