Skip to content

feat(query): add immutable SQL query builder module#22

Draft
ConsoleTVs wants to merge 1 commit into
mainfrom
feat/query-builder
Draft

feat(query): add immutable SQL query builder module#22
ConsoleTVs wants to merge 1 commit into
mainfrom
feat/query-builder

Conversation

@ConsoleTVs

Copy link
Copy Markdown
Member

Summary

New query module providing an immutable, copy-on-write SQL query builder with zero dependencies.

Features

  • SELECT with columns, joins, WHERE, GROUP BY, ORDER BY, LIMIT, OFFSET
  • INSERT with column-value pairs
  • UPDATE with SET and WHERE
  • DELETE with WHERE
  • Raw expressions via Raw (literal SQL) and Expr (SQL with placeholders)
  • Immutable — each method returns a new value, safe to derive from shared bases
  • ? placeholders — compatible with sqlx rebind for any database

Usage

sql, args := query.Select("users").
    Columns("id", "name", query.Raw("COUNT(*) AS total")).
    Join("posts ON posts.user_id = users.id").
    Where("active = ?", true).
    GroupBy("users.id").
    OrderBy("total DESC").
    Limit(10).
    Build()

db.Select(ctx, sql, &users, args...)

Coverage

100% statement coverage.

Zero-dependency query builder with copy-on-write semantics supporting
SELECT, INSERT, UPDATE, and DELETE statements. Supports raw SQL
expressions via Raw and Expr types. Uses ? placeholders.

100% test coverage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant