-
Notifications
You must be signed in to change notification settings - Fork 191
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
Support REPLACE #368
Support REPLACE #368
Conversation
Ok, this is sooo nearly done. I've just copied the tests over from insert to make sure it behaves exactly the same. They're all passing apart from tests that e.g: entry.insert(entry.key).add(entry.select()).toString()
// INSERT INTO "keyv" ("key") SELECT "keyv".* FROM "keyv"
entry.replace(entry.key).add(entry.select()).toString()
// REPLACE INTO "keyv" ("key") (SELECT "keyv".* FROM "keyv") I'm not quite sure why it's not the same for replace, is anyone able to point me in the right direction? |
Fixed 🎉 |
Nice! Merging & pushing new minor version right now. Thanks a bunch! |
* Initial commit * docs(readme): add Greenkeeper badge * Setup entry schema * Use key as primary key * Ensure keys are unique and indexable * Disable timestamps * Add get/set/delete methods * Add clear method * Wait for connection before running queries * Return Boolean for delete method * clear method always resolves to undefined * get method returns undefined on nonexistent keys * Disable logging by default * 0.1.0 * Make invalid connection string more clear * Explicitly use memory for tests * KeyvSQLite => KeyvSqlite * Respect table name * Don't run tests in memory * Accept connection string as contructor argument * Make sure clear only clears current namespace * 0.2.0 * Remove Greenkeeper badge * Test options have expected defaults * Extract keyv-sequelize from keyv-sqlite * Update metadata/readme for Sequelize * Test against SQLite * Set defaults for logging/table * 0.1.0 * Test connection errors are emitted * Extract keyv-sql from keyv-sequelize * Add set method * Add get method * Add delete method * Add clear method * 0.1.0 * Test against SQLite * Ensure keys are unique and indexed as primary keys * Make sure set can update or insert * Use our fork of sql until REPLACE support is merged brianc/node-sql#368 * Keep XO happy * Move back to sql Our changes were merged 🎉 * 0.2.0 * Refactor query into method * Use large busyTimeout with tests Stops 'SQLITE_BUSY: database is locked' errors from creating loads of connections * 0.2.1 * Wrap upserts in if/else so we only run the correct functions Otherwise node-sql will throw errors when building a query that Postgres can't handle * 0.2.2 * Expose opts.dialect rather than sql.dialectName * 0.2.3 * Update to requirable * Lock dependency versions * 0.2.4 * List keyv-postgres and keyv-mysql * 1.0.0 * Fix old Sequelize wording * 1.0.1 * Add keyv logo to header * 1.0.2 * Update sql to the latest version 🚀 (#3) * 1.0.3 * Scope to @keyv * 1.0.4 * Update readme for new scope * 1.0.5 * Update ava to the latest version 🚀 (#7) * Fix JSON quotes in MySQL * 1.0.6 * Allow setting custom VARCHAR key size * Ensure opts.keySize is a number * Test keySize option * 1.1.0 * Add .npmignore * 1.1.1 * Fix bad URLs in package.json (sqlite -> sql) (#10) * 1.1.2 * Update coveralls to the latest version 🚀 (#11) * Update ava to the latest version 🚀 (#12) * Update ava to the latest version 🚀 (#13) * Update ava to the latest version 🚀 (#14) * Update sqlite3 to the latest version 🚀 (#16) * upgrading sqlite3 to version 5.0.2 * creating build yaml for github actions * removing travis ci from build process * updating workflows naming * upgrading pify to version 5.0.0 * updating license to include authors * updating with build status badge * upgrading xo to version 0.45.0 * fixing standard xo issues * fixing standard xo issues * upgrading nyc to version 15.1.0 * upgrading ava to version 3.15.0 * version bump to 1.1.3 * updating authors and github links to jaredwray * updating to include coverage for sql * adding in clean variables and removing rimraf * removing rimraf * removing sqlite * removing sqlite file * moving sql to mono * adding in clean up of sqlite test db * removing from main keyv since importing to mono * validating value coming back Co-authored-by: Luke Childs <lukechilds123@gmail.com> Co-authored-by: greenkeeper[bot] <greenkeeper[bot]@users.noreply.github.com> Co-authored-by: MySidesTheyAreGone <mysidestheyaregone@protonmail.com>
* Initial commit * docs(readme): add Greenkeeper badge * Setup entry schema * Use key as primary key * Ensure keys are unique and indexable * Disable timestamps * Add get/set/delete methods * Add clear method * Wait for connection before running queries * Return Boolean for delete method * clear method always resolves to undefined * get method returns undefined on nonexistent keys * Disable logging by default * 0.1.0 * Make invalid connection string more clear * Explicitly use memory for tests * KeyvSQLite => KeyvSqlite * Respect table name * Don't run tests in memory * Accept connection string as contructor argument * Make sure clear only clears current namespace * 0.2.0 * Remove Greenkeeper badge * Test options have expected defaults * Extract keyv-sequelize from keyv-sqlite * Update metadata/readme for Sequelize * Test against SQLite * Set defaults for logging/table * 0.1.0 * Test connection errors are emitted * Extract keyv-sql from keyv-sequelize * Add set method * Add get method * Add delete method * Add clear method * 0.1.0 * Test against SQLite * Ensure keys are unique and indexed as primary keys * Make sure set can update or insert * Use our fork of sql until REPLACE support is merged brianc/node-sql#368 * Keep XO happy * Move back to sql Our changes were merged 🎉 * 0.2.0 * Refactor query into method * Use large busyTimeout with tests Stops 'SQLITE_BUSY: database is locked' errors from creating loads of connections * 0.2.1 * Wrap upserts in if/else so we only run the correct functions Otherwise node-sql will throw errors when building a query that Postgres can't handle * 0.2.2 * Expose opts.dialect rather than sql.dialectName * 0.2.3 * Update to requirable * Lock dependency versions * 0.2.4 * List keyv-postgres and keyv-mysql * 1.0.0 * Fix old Sequelize wording * 1.0.1 * Add keyv logo to header * 1.0.2 * Update sql to the latest version 🚀 (#3) * 1.0.3 * Scope to @keyv * 1.0.4 * Update readme for new scope * 1.0.5 * Update ava to the latest version 🚀 (#7) * Fix JSON quotes in MySQL * 1.0.6 * Allow setting custom VARCHAR key size * Ensure opts.keySize is a number * Test keySize option * 1.1.0 * Add .npmignore * 1.1.1 * Fix bad URLs in package.json (sqlite -> sql) (#10) * 1.1.2 * Update coveralls to the latest version 🚀 (#11) * Update ava to the latest version 🚀 (#12) * Update ava to the latest version 🚀 (#13) * Update ava to the latest version 🚀 (#14) * Update sqlite3 to the latest version 🚀 (#16) * upgrading sqlite3 to version 5.0.2 * creating build yaml for github actions * removing travis ci from build process * updating workflows naming * upgrading pify to version 5.0.0 * updating license to include authors * updating with build status badge * upgrading xo to version 0.45.0 * fixing standard xo issues * fixing standard xo issues * upgrading nyc to version 15.1.0 * upgrading ava to version 3.15.0 * version bump to 1.1.3 * updating authors and github links to jaredwray * updating to include coverage for sql * adding in clean variables and removing rimraf * removing rimraf * removing sqlite * removing sqlite file * moving sql to mono * adding in clean up of sqlite test db * removing from main keyv since importing to mono * validating value coming back Co-authored-by: Luke Childs <lukechilds123@gmail.com> Co-authored-by: greenkeeper[bot] <greenkeeper[bot]@users.noreply.github.com> Co-authored-by: MySidesTheyAreGone <mysidestheyaregone@protonmail.com>
Resolves #367
Ok, so from the MySQL docs:
https://dev.mysql.com/doc/refman/5.7/en/replace.html
So I've pretty much just copy/pasted all the
INSERT
code and it's working:REPLACE
is a MySQL extension but is also supported by SQLite. I've implemented it in the Postgres dialect so both MySQL and SQLite inherit it to test it works. I'll fix it so it throws if not on MySQL or SQLite dialect.Also need to add tests.