sg: A simple standard SQL generator written in Go.
- Builders
- Generators
- Create view
- Create index
- Create unique index
- Index definition
- Column definition
- Primary key
- Default
- Delete
- Delete from
- Drop table
- Drop view
- Drop event
- Drop procedure
- Insert
- Values
- Alias
- Arg
- From
- Left join
- Right join
- Inner join
- On
- Select
- Order by
- Asc
- Desc
- Asc group
- Desc group
- Group by
- Having
- Update
- Set
- Set eq
- Where
- And
- Or
- Not
- And group
- Or group
- Eq
- Not eq
- Gt
- Gt eq
- Lt
- Lt eq
- Like
- Left like
- Right like
- Instr
- In
- Between and
package main
import (
"fmt"
. "github.com/go-the-way/sg"
)
func main() {
builder := InsertBuilder().
Table(T("table_person")).
Column(C("col1"), C("col2")).
Value(Arg(100), Arg(200))
fmt.Println(builder.Build())
// Output:
// INSERT INTO table_person (col1, col2) VALUES (?, ?) [100 200]
}
package main
import (
"fmt"
. "github.com/go-the-way/sg"
)
func main() {
builder := DeleteBuilder().
Delete(T("t1.*")).
From(As(C("table1"), "t1"), As(C("table2"), "t2")).
Where(AndGroup(Gt("t1.col1", 100), Gt("t2.col2", 200)))
fmt.Println(builder.Build())
// Output:
// DELETE t1.* FROM table1 AS t1, table2 AS t2 WHERE ((t1.col1 > ?) AND (t2.col2 > ?)) [100 200]
}
package main
import (
"fmt"
. "github.com/go-the-way/sg"
)
func main() {
builder := UpdateBuilder().
Update(As(T("table_person"), "t")).
Join(LeftJoin(As(T("table_a"), "ta"), On(C("t.col1 = ta.col1")))).
Set(SetEq("col1", 100), SetEq("col2", 200)).
Where(AndGroup(Eq("a", 100), Eq("b", 200)))
fmt.Println(builder.Build())
// Output:
// UPDATE table_person AS t LEFT JOIN table_a AS ta ON (t.col1 = ta.col1) SET col1 = ?, col2 = ? WHERE ((a = ?) AND (b = ?)) [100 200 100 200]
}
package main
import (
"fmt"
. "github.com/go-the-way/sg"
)
func main() {
builder := SelectBuilder().
Select(C("a"), C("b")).
From(T("table_person")).
Join(LeftJoin(As(T("table_a"), "ta"), On(C("ta.col1 = tb.col1")))).
Where(AndGroup(Eq("a", 100), Eq("b", 200))).
OrderBy(DescGroup(C("a"), C("b")))
fmt.Println(builder.Build())
// Output:
// SELECT a, b FROM table_person LEFT JOIN table_a AS ta ON (ta.col1 = tb.col1) WHERE ((a = ?) AND (b = ?)) ORDER BY a DESC, b DESC [100 200]
}
CreateView(P("vm_nowTime"), P(`select NOW() AS t`)
CreateIndex(false, P("idx_name"), T("table"), C("name"))
CreateUniqueIndex(P("idx_name"), T("table"), C("name"))
IndexDefinition(false, P("idx_name"), C("name"))
ColumnDefinition(P("id"), P("int"), false, true, false, "", "ID")
PrimaryKey(C("id"))
Default(C("1"))
Delete([]Ge{}, T("table_a"))
DeleteFrom(T("table_a"))
DropTable(T("table"))
DropView(T("view"))
DropEvent(T("event"))
DropProcedure(T("procedure"))
Insert(C("table"), C("aa"))
Values(Arg(100))
Alias(C("hello"), "hello_lo")
Arg(100)
From(T("table_a"), T("table_b"))
LeftJoin(As(T("table_a"), "ta"), On(C("ta.col1 = tb.col1"))
RightJoin(As(T("table_a"), "ta"), On(C("ta.col1 = tb.col1"))
InnerJoin(As(T("table_a"), "ta"), On(C("ta.col1 = tb.col1"))
On(C("ta.col1 = tb.col1"))
Select(C("t.col_a"))
OrderBy(AscGroup(C("t.abc"), C("t.xxx")))
Asc(C("t.abc"))
Desc(C("t.abc"))
AscGroup(C("t.abc"), C("t.xxx"))
DescGroup(C("t.abc"), C("t.xxx"))
GroupBy(C("t.abc"), C("t.xyz"))
Having(AndGroup(Eq("a", 1)))
Update(T("table_a"))
Set(C("t.a = t.b"))
SetEq("col1", 100)
Where(AndGroup(Eq("a", 1)))
And(Eq("c", 100))
Or(Eq("c", 100))
Not(Eq("c", 100))
AndGroup(Gt("t1.col1", 100), Gt("t2.col2", 200))
OrGroup(Eq("a", 1), Eq("b", 100))
Eq("a", 1))
NotEq("a", 1))
Gt("a", 1))
Lt("a", 1))
Lt("a", 1))
LtEq("a", 1))
Like("a", 1)
LeftLike("a", 1)
RightLike("a", 1)
Instr("a", 1)
In("a", 1)
BetweenAnd(c, rune(100), rune(100))