Commit Graph
25 Commits
Author SHA1 Message Date
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
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 0542598588 Add returning support on SQL Server 2025-09-25 09:24:16 -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 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 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 cd1b266513 fix #163: CTE API refactory; see issue for details 2024-09-09 01:52:01 +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 Du 96e64e9b7d feature: new builder WhereClause dedicated for WHERE 2024-04-13 23:32:24 +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 eb96df9e68 refs #100 add EXISTS/NOT EXISTS/ANY/SOME/ALL in Cond 2023-04-01 16:43:22 +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 7239db6838 fix #47. add Union and UnionAll methods 2020-07-28 12:01:33 +08:00
Huan Du 88302d2a18 fix #6. fix incorrect marker when nesting builders with PostgreSQL flavor. 2018-02-04 22:48:08 +08:00
Huan Du e219582f5a fix #6. support Postgre-flavor markers. 2018-02-04 21:49:42 +08:00
Huan Du 40f9bb99c7 support nested sql 2017-12-28 12:19:50 +08:00
Huan Du d6f157e3a4 remove useless comments 2017-12-28 01:34:45 +08:00
Huan Du 2f7b2c59bb init 2017-12-28 00:37:13 +08:00