Skip to content

Commit

Permalink
update readme and format code
Browse files Browse the repository at this point in the history
  • Loading branch information
huandu committed Jan 12, 2023
1 parent 674f3da commit 1191d33
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- [Usage](#usage)
- [Basic usage](#basic-usage)
- [Pre-defined SQL builders](#pre-defined-sql-builders)
- [Build SQL for MySQL, PostgreSQL, SQLServer, SQLite, CQL, or ClickHouse](#build-sql-for-mysql-postgresql-sqlserve-sqlite-or-clickhouse)
- [Build SQL for different systems](#build-sql-for-different-systems)
- [Using `Struct` as a light weight ORM](#using-struct-as-a-light-weight-orm)
- [Nested SQL](#nested-sql)
- [Use `sql.Named` in a builder](#use-sqlnamed-in-a-builder)
Expand Down Expand Up @@ -110,9 +110,11 @@ Following are some utility methods to deal with special cases.

To learn how to use builders, check out [examples on GoDoc](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#pkg-examples).

### Build SQL for MySQL, PostgreSQL, SQLServer, SQLite, CQL, or ClickHouse
### Build SQL for different systems

Parameter markers are different in MySQL, PostgreSQL, SQLServer and SQLite. This package provides some methods to set the type of markers (we call it "flavor") in all builders.
SQL syntax and parameter marks vary in different systems. In this package, we introduce a concept called "flavor" to smooth out these difference.

Right now, MySQL, PostgreSQL, SQLServer, SQLite, CQL and ClickHouse are defined in flavor list. Feel free to open issue or send pull request if anyone asks for a new flavor.

By default, all builders uses `DefaultFlavor` to build SQL. The default value is `MySQL`.

Expand Down
8 changes: 4 additions & 4 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ func (args *Args) add(arg interface{}) int {
//
// The format string uses a special syntax to represent arguments.
//
// $? refers successive arguments passed in the call. It works similar as `%v` in `fmt.Sprintf`.
// $0 $1 ... $n refers nth-argument passed in the call. Next $? will use arguments n+1.
// ${name} refers a named argument created by `Named` with `name`.
// $$ is a "$" string.
// $? refers successive arguments passed in the call. It works similar as `%v` in `fmt.Sprintf`.
// $0 $1 ... $n refers nth-argument passed in the call. Next $? will use arguments n+1.
// ${name} refers a named argument created by `Named` with `name`.
// $$ is a "$" string.
func (args *Args) Compile(format string, initialValue ...interface{}) (query string, values []interface{}) {
return args.CompileWithFlavor(format, args.Flavor, initialValue...)
}
Expand Down
20 changes: 11 additions & 9 deletions select.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ func (sb *SelectBuilder) From(table ...string) *SelectBuilder {
// Join sets expressions of JOIN in SELECT.
//
// It builds a JOIN expression like
// JOIN table ON onExpr[0] AND onExpr[1] ...
//
// JOIN table ON onExpr[0] AND onExpr[1] ...
func (sb *SelectBuilder) Join(table string, onExpr ...string) *SelectBuilder {
sb.marker = selectMarkerAfterJoin
return sb.JoinWithOption("", table, onExpr...)
Expand All @@ -119,16 +120,17 @@ func (sb *SelectBuilder) Join(table string, onExpr ...string) *SelectBuilder {
// JoinWithOption sets expressions of JOIN with an option.
//
// It builds a JOIN expression like
// option JOIN table ON onExpr[0] AND onExpr[1] ...
//
// option JOIN table ON onExpr[0] AND onExpr[1] ...
//
// Here is a list of supported options.
// - FullJoin: FULL JOIN
// - FullOuterJoin: FULL OUTER JOIN
// - InnerJoin: INNER JOIN
// - LeftJoin: LEFT JOIN
// - LeftOuterJoin: LEFT OUTER JOIN
// - RightJoin: RIGHT JOIN
// - RightOuterJoin: RIGHT OUTER JOIN
// - FullJoin: FULL JOIN
// - FullOuterJoin: FULL OUTER JOIN
// - InnerJoin: INNER JOIN
// - LeftJoin: LEFT JOIN
// - LeftOuterJoin: LEFT OUTER JOIN
// - RightJoin: RIGHT JOIN
// - RightOuterJoin: RIGHT OUTER JOIN
func (sb *SelectBuilder) JoinWithOption(option JoinOption, table string, onExpr ...string) *SelectBuilder {
sb.joinOptions = append(sb.joinOptions, option)
sb.joinTables = append(sb.joinTables, table)
Expand Down

0 comments on commit 1191d33

Please sign in to comment.