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

upsert support #16

Closed
8 tasks
fwbrasil opened this issue Dec 6, 2015 · 1 comment
Closed
8 tasks

upsert support #16

fwbrasil opened this issue Dec 6, 2015 · 1 comment
Assignees

Comments

@fwbrasil
Copy link
Collaborator

fwbrasil commented Dec 6, 2015

Quill requires multiple queries to use the upsert (insert or update) pattern:

case class Person(name: String)

val count = quote {
  (name: String) => query[Person].filter(_.name == name).size
}
val insert = quote {
  (name: String) => query[Person].insert(_.name -> name)
}
val update = quote {
  (name: String) => query[Person].update(_.name -> name)
}

db.transaction {
  if(db.run(count) == 0)
    db.run(insert)
  else
    db.run(update)
}

It should support a single upsert statement:

val a = quote {
  (name: String) => query[Person].upsert(_.name -> name)
}
db.run(a)
  • Verify if the supported databases (mysql and postgres for now) have support for upserts using a single and atomic sql statement. If not, we might need to redesign the change.
  • Add a new trait similar to Insertable/Updatable
  • Create a new action AST for it.
  • Implement a parser for it.
  • Change the actionUnliftable to support it. The Unliftable instances are responsible for reading the quoted AST when expanding them within another quotation.
  • Change the actionLiftable to support it. Liftable instances are responsible for lifting the query AST to the quoted instance.
  • Fix the compilation warnings of pattern matching not considering the new AST type. Use the implementation for inserts as reference.
  • Implement the integration between SqlIdiom and the specific dialect.
@fwbrasil fwbrasil changed the title "upsert" support upsert support Dec 6, 2015
@fwbrasil fwbrasil added the ready label Dec 19, 2015
@hntd187 hntd187 mentioned this issue Oct 19, 2016
10 tasks
@dsounded
Copy link

any progress ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants