Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: sequelize support is blocked on stored procedures #12120

Closed
jordanlewis opened this issue Dec 6, 2016 · 3 comments · Fixed by cockroachdb/sequelize-cockroachdb#1
Closed
Assignees
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL
Milestone

Comments

@jordanlewis
Copy link
Member

Sequelize's postgres dialect currently uses stored procedures for all database updates: see upsertQuery.

This is a pretty serious blocker to supporting Sequelize out of the box. As an alternative, we could consider creating a simple custom Sequelize dialect that simply overrides upsertQuery from the postgres dialect to do something without stored procedures.

@jordanlewis jordanlewis added the A-sql-pgcompat Semantic compatibility with PostgreSQL label Dec 6, 2016
@cuongdo
Copy link
Contributor

cuongdo commented Dec 8, 2016

Because Sequelize ships with few dialects and it's going to take us a while to support stored procedures, the custom dialect seems like the fastest path to supporting Sequelize.

So, is it possible to create a minimally hacky solution for patching the postgres dialect at runtime, which can be delivered to developers in a reasonable manner?

@cuongdo
Copy link
Contributor

cuongdo commented Dec 12, 2016

FYI upsertQuery creates sequelize_upsert, which executes an upsert with the same return values that MySQL has for INSERT .. ON DUPLICATE KEY UPDATE. Relevant MySQL reference:

http://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html

Relevant quote:

With ON DUPLICATE KEY UPDATE, the affected-rows value per row is 1 if the row is inserted as a new row, 2 if an existing row is updated, and 0 if an existing row is set to its current values.

@bdarnell
Copy link
Contributor

Another option would be to submit a PR upstream to sequelize that would make the postgres dialect use ON CONFLICT DO UPDATE instead of the stored procedure when the server version >= 9.5.0.

@cuongdo cuongdo self-assigned this Jan 17, 2017
@petermattis petermattis added this to the 1.0 milestone Feb 23, 2017
@tbg tbg mentioned this issue Feb 24, 2017
4 tasks
cuongdo pushed a commit to cockroachdb/sequelize-cockroachdb that referenced this issue Mar 23, 2017
The Postgres dialect for Sequelize uses a stored procedure to implement
upserts, for compatibility with PostgreSQL before 9.5. CockroachDB has
upsert but no stored procedures, so this monkey patch for the built-in
Sequelize dialect replaces Sequelize's Model.upsert() with a version
that uses `INSERT ... ON CONFLICT DO UPDATE SET`, which CockroachDB does
support.

require()ing the package multiple times should be fine, as `index.js`
is idempotent.

Note that tests will not pass until cockroachdb/cockroach#13962 is
fixed.

Resolves cockroachdb/cockroach#12120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants