Skip to content

Conversation

@yagodorea
Copy link
Owner

@yagodorea yagodorea commented Jul 12, 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?
  • 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?)

@yagodorea yagodorea merged commit 0362654 into v6 Jul 17, 2025
53 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.

2 participants