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

Use SqlFragment type alias everywhere #29

Merged
merged 1 commit into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ _ZIO JDBC_ is a small, idiomatic ZIO interface to JDBC, providing a pleasant and
```scala
val age = 42

val ex0: Sql[ZResultSet] = sql"create table if not exists users(name varchar(255), age int)"
val ex0: SqlFragment = sql"create table if not exists users(name varchar(255), age int)"

// Creating SQL statements using interpolation:
val ex1: Sql[ZResultSet] = sql"select * from users where age = $age"
val ex1: SqlFragment = sql"select * from users where age = $age"

// Selecting into tuples:
val ex2: Sql[(String, Int)] = sql"select name, age from users".as[(String, Int)]

// Inserting from tuples:
val ex3: Sql[ZResultSet] = sql"insert into users (name, age)".values(("John", 42))
val ex3: SqlFragment = sql"insert into users (name, age)".values(("John", 42))

// dropping table
val ex4: Sql[ZResultSet] = sql"drop table if exists users"
val ex4: SqlFragment = sql"drop table if exists users"
```


Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/zio/jdbc/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ package object jdbc {
/**
* Converts a String into a pure SQL expression
*/
implicit def stringToSql(s: String): Sql[ZResultSet] = Sql(Chunk(Sql.Segment.Syntax(s)), identity)
implicit def stringToSql(s: String): SqlFragment = Sql(Chunk(Sql.Segment.Syntax(s)), identity)

/**
* Executes a SQL delete query.
*/
def delete(sql: Sql[ZResultSet]): ZIO[ZConnection, Throwable, Long] =
def delete(sql: SqlFragment): ZIO[ZConnection, Throwable, Long] =
for {
connection <- ZIO.service[ZConnection]
result <- connection.executeSqlWith(sql)(_.executeLargeUpdate())
Expand All @@ -45,7 +45,7 @@ package object jdbc {
/**
* Executes a SQL statement, such as one that creates a table.
*/
def execute(sql: Sql[ZResultSet]): ZIO[ZConnection, Throwable, Unit] =
def execute(sql: SqlFragment): ZIO[ZConnection, Throwable, Unit] =
for {
connection <- ZIO.service[ZConnection]
_ <- connection.executeSqlWith(sql)(_.executeUpdate())
Expand All @@ -54,7 +54,7 @@ package object jdbc {
/**
* Performs a SQL update query, returning a count of rows updated.
*/
def insert(sql: Sql[ZResultSet]): ZIO[ZConnection, Throwable, Long] =
def insert(sql: SqlFragment): ZIO[ZConnection, Throwable, Long] =
for {
connection <- ZIO.service[ZConnection]
result <- connection.executeSqlWith(sql)(_.executeLargeUpdate())
Expand Down Expand Up @@ -111,7 +111,7 @@ package object jdbc {
/**
* Performs a SQL update query, returning a count of rows updated.
*/
def update(sql: Sql[ZResultSet]): ZIO[ZConnection, Throwable, Long] =
def update(sql: SqlFragment): ZIO[ZConnection, Throwable, Long] =
for {
connection <- ZIO.service[ZConnection]
result <- connection.executeSqlWith(sql)(_.executeLargeUpdate())
Expand Down
8 changes: 4 additions & 4 deletions examples/src/main/scala/zio/jdbc/examples/Basic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import zio.jdbc._
object Basic {
val age = 42

val ex0: Sql[ZResultSet] = sql"create table if not exists users(name varchar(255), age int)"
val ex0: SqlFragment = sql"create table if not exists users(name varchar(255), age int)"

// Creating SQL statements using interpolation:
val ex1: Sql[ZResultSet] = sql"select * from users where age = $age"
val ex1: SqlFragment = sql"select * from users where age = $age"

// Selecting into tuples:
val ex2: Sql[(String, Int)] = sql"select name, age from users".as[(String, Int)]

// Inserting from tuples:
val ex3: Sql[ZResultSet] = sql"insert into users (name, age)".values(("John", 42))
val ex3: SqlFragment = sql"insert into users (name, age)".values(("John", 42))

// dropping table
val ex4: Sql[ZResultSet] = sql"drop table if exists users"
val ex4: SqlFragment = sql"drop table if exists users"

// Composing requests:
val keyColumn = "key"
Expand Down