40 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
zhangyongding 18d53180f6 change the Oracle select to use OFFSET...FETCH 2026-01-22 08:35:52 +08:00
zhangyongding f8440f9506 fix oracle limit bug 2025-10-20 18:13:44 +08:00
Huan Du f3798970f7 Add nested JOIN example to README and tests
Add documentation and test example demonstrating how to use BuilderAs
to create nested JOIN queries. This is useful when joining with filtered
or transformed datasets.

fix #217
2025-10-10 16:27:13 +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
Edouard Schweisguth 542af0bd67 Add nil check regression for BuildWithFlavor 2025-06-25 11:35:45 +02:00
Edouard Schweisguth a0cb9722f3 Add regression test 2025-06-25 11:27:06 +02:00
Huan Du 8ed4b5374f fix #192 Add new flavor Doris 2025-03-20 19:05:19 +08: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 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
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
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 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 61cf17e67a 修复分页查询时存在order by返回结果不正确的bug 2023-10-10 20:49:21 +08:00
Huan Du 769091c858 refs #115: Generate SQL only when necessary values are set 2023-07-22 20:50:59 +08:00
Huan Du 0b1c445a5c refs #98 add new flavor Presto 2023-03-27 23:17:33 +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
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
Aleksander Zaruczewski 157445026c Fix warnings and typos 2022-02-17 16:07:23 +03: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
Huan Du 402f354140 fix #35. do not escape cols by default. 2019-10-25 18:32:34 +08:00
Florian Lechner 867c0124b5 added test case for limit offset 2019-07-21 12:19:07 +02:00
Huan Du 5e6c0741f7 fix #13. SelectBuilder supports Join and JoinWithOption. 2018-11-23 16:37:46 +08:00
Huan Du f039956b9d add SelectBuilder#BuilderAs to make embedding builders easier 2017-12-31 20:38:03 +08:00
Huan Du 59e26deed3 provide Flatten; support sql.NamedArg 2017-12-28 18:26:21 +08:00
Huan Du 40f9bb99c7 support nested sql 2017-12-28 12:19:50 +08:00
Huan Du be8a7cbb32 support DISTINCT 2017-12-28 01:39:42 +08:00
Huan Du 8193c41814 add tests and doc 2017-12-28 01:33:30 +08:00