63 Commits
Author SHA1 Message Date
zeekay 74627ec1a2 Fork huandu/go-sqlbuilder v1.39.1 to hanzoai/sqlbuilder; debrand ClickHouse flavor -> Datastore
- go.mod module path -> github.com/hanzoai/sqlbuilder (package name kept: sqlbuilder)
- Rename exported Flavor constant ClickHouse -> Datastore (same iota ordinal 6,
  behavior byte-identical): const decl, all case labels (Interpolate/Quote/
  PrepareInsertIgnore/args/select/union), Flavor.String() literal "ClickHouse"
  -> "Datastore", and the name<->flavor test map.
- Rename unexported dialect helper clickhouseInterpolate -> datastoreInterpolate.
- Rename example ExampleInsertBuilder_insertIgnore_clickhouse -> _datastore.
- Update tests + README flavor list to Datastore.
- Keep upstream MIT LICENSE; add NOTICE recording the fork + rename.

Dialect SQL output unchanged; only the identifier is renamed.
2026-07-12 18:00:41 -07:00
3f3e5aa6de Update select.go
Co-authored-by: Hanzo Dev <[email protected]>
2026-01-27 08:16:05 +08:00
zhangyongding 18d53180f6 change the Oracle select to use OFFSET...FETCH 2026-01-22 08:35:52 +08:00
Huan Du 053369bda3 fix #229: update doc on Where to avoid confusion 2026-01-20 11:48:29 +08:00
Huan Du af5ffafd92 fix #223: mark OrderBy as "not recommended" rather than deprecated 2025-12-29 11:20:02 +08:00
zhangyongding f8440f9506 fix oracle limit bug 2025-10-20 18:13:44 +08:00
Huan Du 6db1108ec3 Add OrderByAsc and OrderByDesc methods to all builders
Implement new OrderByAsc(col) and OrderByDesc(col) methods for
SelectBuilder, UnionBuilder, UpdateBuilder, and DeleteBuilder. These
methods allow chaining multiple ORDER BY columns with different sort
directions, addressing the limitation where the old OrderBy/Asc/Desc
pattern could only apply a single direction to all columns.

Key changes:
- Add OrderByAsc(col string) and OrderByDesc(col string) to all four builders
- Each method appends the column with explicit ASC/DESC suffix
- Support chaining for complex ordering: OrderByDesc("score").OrderByAsc("name")
- Deprecate OrderBy/Asc/Desc methods with clear migration guidance
- Add comprehensive tests (TestSelectBuilder_OrderByAscDesc)
- Add example functions demonstrating usage
- Update all existing examples to use new API
- Update README.md with new "Build ORDER BY clause" section

This design is inspired by MyBatis-Plus and provides a more intuitive
and flexible API for handling multiple ORDER BY columns with different
sorting directions.

fix #214
2025-10-10 16:13:30 +08:00
Huan Du 18f7db8816 fix #211: Support clone (deep copy) in all builders 2025-09-17 16:19:09 +08:00
Huan Du 8ed4b5374f fix #192 Add new flavor Doris 2025-03-20 19:05:19 +08:00
Bar Weiss 0f5ba50c2c Add some in-code documentation 2025-03-20 10:47:05 +02:00
Bar Weiss feef77c099 Fix the order of LIMIT and OFFSET clauses when using the Presto flavor (issue #195)
Queries that have both a limit and an offset build a query with a limit clause *before* the offset clause.

```go
fmt.Println(Select("*").From("table").Offset(5).Limit(10))
// SELECT * FROM table LIMIT 10 OFFSET 5
```

This seems to generate syntax errors in Trino. [Presto documentation specifies OFFSET before LIMIT](https://prestodb.io/docs/current/sql/select.html#limit-clause) in the SELECT statement documentation too, but is not very explicit about the reverse not being supported.

If the OFFSET and LIMIT clauses are swapped, the query succeeds.

Expected:

```go
fmt.Println(Select("*").From("table").Offset(5).Limit(10))
// SELECT * FROM table OFFSET 5 LIMIT 10
```
2025-03-20 10:32:26 +02:00
Huan DuandGitHub 3c20969dde Merge pull request #189 from huandu/feature/limit-offset-using-args
Fix #186: use args in LIMIT and/or OFFSET expression
2025-02-11 15:11:22 +08:00
Huan Du ee087fd12b ignore empty values and expressions to prevent syntax error 2025-01-26 15:35:02 +08:00
Huan Du 827392d26d fix #186: use args in LIMIT and/or OFFSET expression 2025-01-26 15:06:21 +08:00
Huan Du e0939dbf05 fix #181: Support LATERAL keyword 2024-12-01 03:25:59 +08:00
Huan Du e3eef72bb4 refs #176: Automatically ref names of CTETables in DELETE and UPDATE statement 2024-11-02 23:03:02 +08:00
Vasily Rodionov 98718aad2d new: Added Flavor method to Builder interface 2024-10-31 15:23:25 +05:00
Vasily Rodionov b28a583417 new: flavor getters 2024-10-30 20:39:31 +05:00
Vasily Rodionov d21fa10b30 test: Added test cases for empty strings in where clause 2024-10-27 22:20:40 +05:00
Huan Du 03e80e6f8c refs #164: new API SelectMore to add more cols to SELECT after calling Select() 2024-09-09 02:05:14 +08:00
Huan Du cd1b266513 fix #163: CTE API refactory; see issue for details 2024-09-09 01:52:01 +08:00
Huan Du e8528206c0 fix: #160 SelectBuilder.With appends table names to FROM 2024-08-04 20:29:26 +08:00
Huan Du 85be89ace1 support multiple tables in a WITH clause 2024-07-24 16:54:41 +08:00
Huan Du 75c6f8c1e4 implement CTEBuilder 2024-07-06 23:58:26 +08:00
Huan Du fbe2e35f71 fix #149: avoid to generate invalid WHERE clause if andExpr is empty 2024-05-20 11:34:51 +08:00
Huan DuandGitHub 20c2b710b3 Merge pull request #146 from zhangyongding/master
Optimize paging syntax for Informix SELECT.
2024-04-15 11:53:04 +08:00
Huan Du 96e64e9b7d feature: new builder WhereClause dedicated for WHERE 2024-04-13 23:32:24 +08:00
maixl 72476d8c0a 优化informix分页查询语句,更优雅 2024-04-10 17:36:29 +08:00
maixl 8d52201d6a fix bug 2024-03-29 10:26:29 +08:00
maixl 2d88cfe780 支持informix 2024-03-19 10:50:29 +08:00
Huan Du 3706314572 fix #134: Add new Num* methods in CRUD builders to count number of required clause 2023-11-30 23:57:25 +08:00
maixl 1490edd776 修复分页查询的的bug 2023-10-16 08:32:05 +08:00
maixl 61cf17e67a 修复分页查询时存在order by返回结果不正确的bug 2023-10-10 20:49:21 +08:00
zhangyd 89af7205a9 oracle的limit和offset改为固定参数 2023-09-19 09:11:42 +08:00
zhangyd 39fc042a98 修复多表查询时oracle分页的bug 2023-09-18 14:09:48 +08:00
zhangyd f5180d1584 fix bug 2023-09-15 21:06:16 +08:00
zhangyd b317170923 oracle support limit 2023-09-15 18:10:54 +08:00
Huan Du 769091c858 refs #115: Generate SQL only when necessary values are set 2023-07-22 20:50:59 +08:00
Huan DuandGitHub cb38c02175 Merge pull request #102 from huandu/feature-more-cond
fix #100 Add EXISTS/NOT EXISTS/ANY/SOME/ALL in `Cond`
2023-04-01 16:57:49 +08:00
Huan Du eb96df9e68 refs #100 add EXISTS/NOT EXISTS/ANY/SOME/ALL in Cond 2023-04-01 16:43:22 +08:00
Huan Du 0b1c445a5c refs #98 add new flavor Presto 2023-03-27 23:17:33 +08:00
Huan Du 59650fe906 update readme and format code 2023-01-12 17:08:08 +08:00
Spencer Connaughton 8880301f5b Merge remote-tracking branch 'upstream/master'
# Conflicts:
#	README.md
#	args.go
#	flavor.go
#	insert_test.go
#	interpolate.go
#	interpolate_test.go
#	select_test.go
#	struct.go
#	struct_test.go
2023-01-05 10:19:05 -05:00
csuzhang 561104398a support ClickHouse Grammar 2022-12-12 17:34:23 +08:00
39a4b2509b Merge remote-tracking branch 'upstream/master' (#2)
* ignore unexported fields that are not embedded structs

* fix #74 [BREAKING CHANGE] Select#GroupBy and Select#OrderBy behavior change.

Previous, GroupBy and OrderBy only keep the columns in the last call. Now, all columns are kept.

* fix #75 add Struct#Columns/ColumnsForTag and Struct#Values/ValuesForTag

* remove a call to StructField.IsExported as it is not in go1.13

* refs #78 add new `fieldas` tag to set AS name for SELECT

* update docs

* fix #81 refactory struct field parser to make fieldas correct in all cases

* Add Gitter badge

* Fix insert ignore for postgres and sqlite.

* fix test

Co-authored-by: Michał Dobaczewski <[email protected]>
Co-authored-by: Huan Du <[email protected]>
Co-authored-by: The Gitter Badger <[email protected]>
Co-authored-by: Zhong Ren <[email protected]>
2022-11-30 10:57:35 -05:00
Spencer ConnaughtonandGitHub 0f54cd520c Add CQL support (#1)
* Add CQL flavor.

* Add support for CQL argument compilation.

* Adopt substests for interpolation tests.

* Add support for CQL interpolation.

* Add support for CQL blobs.

https://docs.datastax.com/en/cql-oss/3.x/cql/cql_reference/blob_r.html

* Add CQL timestamp interpolation support.

https://docs.datastax.com/en/cql-oss/3.x/cql/cql_reference/timestamp_type_r.html

* Add builder test for CQL.

* Add support for the NOW function.

https://docs.datastax.com/en/cql-oss/3.3/cql/cql_reference/timeuuid_functions_r.html?hl=now

* Add support for CQL update IF statement.

https://docs.datastax.com/en/cql-oss/3.3/cql/cql_reference/cqlUpdate.html#Conditionallyupdatingcolumns

* Drop table prefixes for CQL SELECTs.

* Switch to single quoting for CQL queries.

https://docs.datastax.com/en/cql-oss/3.3/cql/cql_reference/escape_char_r.html

* Update documentation.

* Use valid CQL in tests.

* Support CQL LIMIT.
2022-09-08 14:39:35 -04:00
Huan Du d444898018 fix #74 [BREAKING CHANGE] Select#GroupBy and Select#OrderBy behavior change.
Previous, GroupBy and OrderBy only keep the columns in the last call. Now, all columns are kept.
2022-06-23 12:50:48 +08:00
Huan Du 5cf00e9d1d add ORDER BY 1 for SQL Server if Limit() is set but OrderBy() is not 2021-07-27 22:46:02 +08:00
Huan Du 3e007c306f refs #64 add SQLServer flavor 2021-07-25 03:28:33 +08:00
Huan Du b15ca56b4d refs #48 #49 #53: add new method SQL in all builders
All builders add a new method called SQL to enable us to add any
arbitrary SQL when building. It's quite useful when we are using some
kinds of extension syntax or add special comments in SQL.
2021-02-04 00:07:55 +08:00