Last active
April 5, 2022 06:37
-
-
Save supermanue/46550b91f0537459bf196cfa9653b67b to your computer and use it in GitHub Desktop.
SQL Queries
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
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