22 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
Istvan Kiss 7c3be4718b test From on UpdateBuilder 2026-01-19 16:08:30 +01: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
Bugadinho 2b16f0cd14 Add tests for returning on SQL Server 2025-09-25 09:24:32 -03:00
Huan Du 18f7db8816 fix #211: Support clone (deep copy) in all builders 2025-09-17 16:19:09 +08:00
Huan Du 8e5ccbbee2 feat: implement Returning method for UpdateBuilder and DeleteBuilder
Fixes #210

This commit adds the Returning method to both UpdateBuilder and DeleteBuilder,
following the same implementation pattern as InsertBuilder.

Changes:
- Add returning field to UpdateBuilder and DeleteBuilder structs
- Add updateMarkerAfterReturning and deleteMarkerAfterReturning markers
- Implement Returning methods for both builders
- Add RETURNING clause support for PostgreSQL and SQLite flavors
- Add comprehensive test coverage including:
  - Basic functionality tests
  - Flavor-specific behavior tests
  - Edge cases (empty, single, multiple columns)
  - Complex scenarios (ORDER BY, LIMIT, CTE)
  - SQL injection compatibility
  - Method chaining validation

The RETURNING clause is properly positioned after LIMIT and is ignored
for database flavors that don't support it (MySQL, SQL Server, CQL,
ClickHouse, Presto).

Example usage:
  ub := Update("users").Set("name = ?", "John").Where("id = ?", 1).Returning("id", "updated_at")
  db := DeleteFrom("users").Where("status = ?", "inactive").Returning("id", "deleted_at")
2025-07-24 16:01:37 +00:00
Huan Du 827392d26d fix #186: use args in LIMIT and/or OFFSET expression 2025-01-26 15:06:21 +08:00
Huan Du bbd370c39c fix #184: fix SQL syntax error in WITH ... UPDATE ... FROM 2024-12-05 13:00:55 +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 cd1b266513 fix #163: CTE API refactory; see issue for details 2024-09-09 01:52:01 +08:00
Huan Du 96e64e9b7d feature: new builder WhereClause dedicated for WHERE 2024-04-13 23:32:24 +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
Huan Du 9d74991669 fix #59 support field mapper for Struct 2021-02-21 20:18:09 +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
petersunbag 4fc90bd491 add table in TestUpdateBuilder_SetMore 2019-08-19 19:10:14 +08:00
petersunbag 36ce8a8599 SetAppend -> SetMore 2019-08-19 18:11:30 +08:00
petersunbag 00dbc17646 SetAppend -> SetMore 2019-08-19 18:08:43 +08:00
petersunbag 918aaddf83 add SetAppend in UpdateBuilder 2019-08-15 16:39:14 +08:00
Huan Du ec2d60bdf3 add test cases 2017-12-31 01:30:01 +08:00
Huan Du e121c6d3dd more tests 2017-12-28 01:56:44 +08:00
Huan Du 8193c41814 add tests and doc 2017-12-28 01:33:30 +08:00