Skip to content

Instantly share code, notes, and snippets.

@supermanue
Last active April 5, 2022 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supermanue/46550b91f0537459bf196cfa9653b67b to your computer and use it in GitHub Desktop.
Save supermanue/46550b91f0537459bf196cfa9653b67b to your computer and use it in GitHub Desktop.
SQL Queries
import zio.experiment.adapter.model.{User => UserStored}
object SQL {
def get(id: Int): Query0[UserStored] =
sql"""SELECT * FROM USERS WHERE ID = $id """.query[UserStored]
def create(user: UserStored): Update0 =
sql"""INSERT INTO USERS (id, name) VALUES (${user.id}, ${user.name})""".update
def delete(id: Int): Update0 =
sql"""DELETE FROM USERS WHERE id = $id""".update
def createUsersTable: doobie.Update0 =
sql"""CREATE TABLE USERS (id Int, name VARCHAR NOT NULL)""".update
def dropUsersTable: doobie.Update0 =
sql"""DROP TABLE IF EXISTS USERS""".update
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment