Skip to content

Conversation

yagodorea
Copy link
Owner

@yagodorea yagodorea commented Jul 6, 2025

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • If a documentation update is necessary, have you opened a PR to the documentation repository? docs: query builder sequelize/website#804
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Does the name of your PR follow our conventions?

Description of Changes

Adds a simple query builder to sequelize static models. Basic functionality:

  • Model.select() -> will instantiate the query builder for chaining
  • .attributes(['a', 'b']) -> select attributes
  • .where({c: true, d: 1}) -> specify where conditions
  • .getQuery() -> return plain SQL
  • Add an .execute() method that will run the raw sql instead of returning it
  • Support .limit() and .offset()
  • Support .orderBy([['a', 'DESC'], ['b', 'ASC']])
  • Support .groupBy(['a', 'b', 1, 2])
  • Support .having()
  • Support .andHaving()
  • Support .include() with custom join logic

Future improvements/additions:

  • Support returning the Model objects instead of raw result
  • Support .andWhere using Sequelize.where(col, op, value), Sequelize.literal() and WhereBrackets as per proposal
  • Support .orWhere, block simultaneous usage with .andWhere
  • Allow QueryBuilder on right-hand side of where options as a subquery/literal (DynamicValues?)
  • Support CTEs

@yagodorea yagodorea marked this pull request as draft July 6, 2025 15:33
@yagodorea yagodorea force-pushed the yagodorea/querybuilder branch from 8591185 to cb21278 Compare July 6, 2025 15:40
@yagodorea yagodorea marked this pull request as ready for review July 26, 2025 13:27
@yagodorea yagodorea merged commit ec77a74 into main Jul 30, 2025
47 of 48 checks passed
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