Skip to content

Commit

Permalink
Merge pull request #29 from zagyi/use-type-alias
Browse files Browse the repository at this point in the history
Use SqlFragment type alias everywhere
  • Loading branch information
jdegoes authored Feb 18, 2022
2 parents 6899569 + 221d42d commit 4be1152
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
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

0 comments on commit 4be1152

Please sign in to comment.