Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NQDmA3mwGfL83pbg9WQ6ey
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Changes
I ran the code examples on these pages against
@sequelize/corebuilt from the currentmainof sequelize/sequelize (and7.0.0-alpha.48from npm, which gives the same results). For SQL I used the query generator of the postgres and mysql dialects, and real queries on SQLite in memory. These examples either throw or show SQL that Sequelize does not generate. There is no issue for this; the list below describes each problem.querying/select-in-depth.md
subQuery, notsubquery. Withsubquery: falsethe option is ignored, the subquery stays, and the query fails withno such column: projects.name. WithsubQuery: falseit runs as a plain JOIN.Op.inhad no parentheses and noFROMclause. Sequelize inserts anOp.inliteral as is, so this produced"id" IN SELECT ..., which is a syntax error. I added the parentheses and theFROM "projects". On SQLite it now returns the users who have "Project 1".findOnereturns one instance, soJSON.stringify(author[0])printedundefined. It is nowJSON.stringify(author).querying/sub-queries.md
@sequelize/decorators-legacy, which does not exist (npm returns 404). They are exported from@sequelize/core/decorators-legacy, like on the other pages.NonAttributewas used but not imported.storage: ':memory:'without the pool settings throws "SQLite is configured to use a temporary database, but the pool is configured to close idle connections". I added the samepooloption that the SQLite page recommends.Op.inliterals got the same missing parentheses fix as above. The first example now returns the expected post. The second one, which interpolates${type}, still fails onmainbecause the interpolated value gets validated against theidattribute's INTEGER type ('Laugh' is not a valid integer). That is a problem in core, not in the docs, so I left the rest of that example as it was.querying/raw-queries.mdx
sql.uuidV4andsql.randomare values, not functions.${sql.uuidV4()}and${sql.random()}throwTypeError: ... is not a function. With${sql.uuidV4}postgres generatesgen_random_uuid(), and with${sql.random}it generatesRANDOM(), which matches the table on the page.sql.join(values, sql,)does not add parentheses, soIN ${...}generatedstatus IN 'active', 'pending'. I added the parentheses, the same way the example just above does it.sql.identifier(Model)example importedUserfrom@sequelize/core(no such export) and then usedModelwithout importing it. It now importsModel.querying/json.mdx
'gameData.passwords[0]': 0451is a legacy octal literal. In TypeScript and ES modules it is a syntax error (TS1121: Octal literals are not allowed). In sloppy-mode JS it is297, so the query compared against'297'. I changed it to the string'0451', which generates= '"0451"'.age: 18is stringified to JSON like any other value, so the comparison is= '18', not= 18. Postgres has nojsonb = integeroperator.or(SQL_NULL, JSON_NULL)example, the JSON null check was shown as= '"null"'. That is the JSON string"null", which the table further down says does not match. Sequelize compares against'null'.querying/operators.mdx
LIKEexample the generated SQL showed the escaped JS string (10\\%,'\\') instead of the SQL Sequelize produces for postgres (10\%,'\'). The second example at the bottom of the page already shows the right form.other-topics/scopes.md (v7 and v6)
sequelizeandmodelNamewere nested insidescopes, soModel.initthrows ("Model.init expects a Sequelize instance" in v7, "No Sequelize instance passed" in v6.37.8). I moved them up one level. With that changeModel.initsucceeds. I tested it with thedeleted,randomandaccessLevelscopes (I left outactiveUsersbecause it needs aUsermodel).How I checked it
@sequelize/core,@sequelize/postgres,@sequelize/mysqland@sequelize/sqlite3from sequelize/sequelizemain(b7f5857). Then I compared the generated SQL fromqueryGenerator.whereQueryandqueryGenerator.escapeagainst each corrected snippet.select-in-depthandsub-queriesexamples on SQLite in memory with seeded rows, before and after the change.sql.identifierimport withtsc5.9. The old versions fail with TS2307, TS2304 and TS2614. The new versions pass.sequelize@6.37.8.prettier --checkpasses on the changed files. The lint-staged hook also ran on commit.