Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
fokot committed Nov 27, 2020
2 parents 5a3f304 + a085582 commit bf5b426
Show file tree
Hide file tree
Showing 21 changed files with 1,481 additions and 310 deletions.
20 changes: 10 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -276,28 +276,28 @@ workflows:
filters:
<<: *filter_tags
- mdoc:
requires:
- lint
# requires:
# - lint
filters:
<<: *filter_tags
- test_212_jdk8_jvm:
requires:
- lint
# requires:
# - lint
filters:
<<: *filter_tags
- test_213_jdk8_jvm:
requires:
- lint
# requires:
# - lint
filters:
<<: *filter_tags
- test_212_jdk11_jvm:
requires:
- lint
# requires:
# - lint
filters:
<<: *filter_tags
- test_213_jdk11_jvm:
requires:
- lint
# requires:
# - lint
filters:
<<: *filter_tags
- release:
Expand Down
58 changes: 53 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@
| --- | --- |
| [![Build Status][badge-ci]][link-ci] | [![badge-discord]][link-discord] |

## Current status: pre-0.1 (no release yet)

### Progress report towards 0.1

:heavy_check_mark: - good to go

:white_check_mark: - some more work needed

#### General features:
Feature | Progress
:------------ | :-------------
Type-safe schema | :heavy_check_mark:
Type-safe DSL | :white_check_mark:
Running Reads | :heavy_check_mark:
Running Deletes | :heavy_check_mark:
Running Updates | :heavy_check_mark:
Running Inserts |
Transactions |
Connection pool |

#### Db-specific features:

Feature | PostgreSQL | SQL Server | Oracle | MySQL
:------------ | :-------------| :-------------| :-------------| :-------------
Render Read | :white_check_mark: | :white_check_mark: | |
Render Delete | :white_check_mark: | | |
Render Update | :white_check_mark: | | |
Render Insert | | | |
Functions | :white_check_mark: | | |
Types | | | |
Operators | | | |

## What is ZIO SQL?
ZIO SQL lets you write type-safe, type-inferred, and composable SQL queries in ordinary Scala, helping you prevent persistence bugs before they happen, and leverage your IDE to make writing SQL productive, safe, and fun.

* **Type-safety**. ZIO SQL queries are type-safe by construction. Most classes of bugs can be detected at compile-time, shortening your feedback loop and helping you use your IDE to write correct queries.
Expand All @@ -20,12 +53,27 @@ For the JDBC module:

ZIO SQL does not offer Language Integrated Queries (LINQ) or similar functionality. It is intended only as a data model for representing SQL queries and an accompanying lightweight JDBC-based executor.

If you want to learn more, please check out:

- [ZIO SQL Homepage](https://zio.github.io/zio-sql)
- [ZIO SQL Discord](https://discord.gg/2ccFBr4)

[badge-ci]: https://circleci.com/gh/zio/zio-sql/tree/master.svg?style=svg
[badge-discord]: https://img.shields.io/discord/629491597070827530?logo=discord "chat on discord"
[link-ci]: https://circleci.com/gh/zio/zio-sql/tree/master
[link-discord]: https://discord.gg/2ccFBr4 "Discord"

## Setup
Prerequisites (installed):

| Technology | Version |
| ------------ | ---------------- |
| sbt | 1.4.3 |
| Docker | 3.1 |

To set up the project follow below steps:
1. Fork the repository.
2. Setup the upstream (Extended instructions can be followed [here](https://docs.github.com/en/free-pro-team@latest/github/getting-started-with-github/fork-a-repo)).
3. Make sure you have installed `sbt` and `Docker`.
4. In project directory execute `sbt test`.
5. Pick up an issue & you are ready to go!

If you want to learn more, please check out:

- [ZIO SQL Homepage](https://zio.github.io/zio-sql)
- [ZIO SQL Discord](https://discord.gg/2ccFBr4)
7 changes: 6 additions & 1 deletion core/jvm/src/main/scala/zio/sql/Sql.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ trait Sql extends SelectModule with DeleteModule with UpdateModule with ExprModu
def select[F, A, B <: SelectionSet[A]](selection: Selection[F, A, B]): SelectBuilder[F, A, B] =
SelectBuilder(selection)

def deleteFrom[F[_], A, B](table: Table.Source.Aux[F, A, B]): DeleteBuilder[F, A, B] = DeleteBuilder(table)
def deleteFrom[F[_], A, B](table: Table.Source.Aux[F, A, B]): Delete[A] = Delete(table, true)

def update[A](table: Table.Aux[A]): UpdateBuilder[A] = UpdateBuilder(table)

def renderDelete(delete: self.Delete[_]): String

def renderRead(read: self.Read[_]): String

def renderUpdate(update: self.Update[_]): String

}
7 changes: 2 additions & 5 deletions core/jvm/src/main/scala/zio/sql/delete.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package zio.sql

trait DeleteModule { self: ExprModule with TableModule =>

sealed case class DeleteBuilder[F[_], A, B](table: Table.Aux[A]) {
def where[F1](expr: Expr[F1, A, Boolean]): Delete[F1, A] = Delete(table, expr)
sealed case class Delete[A](table: Table.Aux[A], whereExpr: Expr[_, A, Boolean]) {
def where[F](expr: Expr[F, A, Boolean]): Delete[A] = Delete(table, expr)
}

sealed case class Delete[F, A](table: Table.Aux[A], whereExpr: Expr[F, A, Boolean])

}
23 changes: 17 additions & 6 deletions core/jvm/src/main/scala/zio/sql/expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ trait ExprModule extends NewtypesModule with FeaturesModule with OpsModule {
def <=[F2, A1 <: A, B1 >: B](that: Expr[F2, A1, B1]): Expr[F :||: F2, A1, Boolean] =
Expr.Relational(self, that, RelationalOp.LessThanEqual)

def like[F2, A1 <: A, B1 >: B](that: Expr[F2, A1, B1]): Expr[F :||: F2, A1, Boolean] =
Expr.Relational(self, that, RelationalOp.Like)

def &[F2, A1 <: A, B1 >: B](that: Expr[F2, A1, B1])(implicit ev: IsIntegral[B1]): Expr[F :||: F2, A1, B1] =
Expr.Binary(self, that, BinaryOp.AndBit[B1]())

Expand Down Expand Up @@ -158,6 +161,10 @@ trait ExprModule extends NewtypesModule with FeaturesModule with OpsModule {
def typeTag: TypeTag[Z] = implicitly[TypeTag[Z]]
}

sealed case class FunctionCall0[F, A, B, Z: TypeTag](function: FunctionDef[B, Z]) extends InvariantExpr[F, A, Z] {
def typeTag: TypeTag[Z] = implicitly[TypeTag[Z]]
}

sealed case class FunctionCall1[F, A, B, Z: TypeTag](param: Expr[F, A, B], function: FunctionDef[B, Z])
extends InvariantExpr[F, A, Z] {
def typeTag: TypeTag[Z] = implicitly[TypeTag[Z]]
Expand Down Expand Up @@ -210,6 +217,9 @@ trait ExprModule extends NewtypesModule with FeaturesModule with OpsModule {

sealed case class FunctionDef[-A, +B](name: FunctionName) { self =>

def apply[Source, B1 >: B]()(implicit typeTag: TypeTag[B1]): Expr[Unit, Source, B1] =
Expr.FunctionCall0(self: FunctionDef[A, B1])

def apply[F, Source, B1 >: B](param1: Expr[F, Source, A])(implicit typeTag: TypeTag[B1]): Expr[F, Source, B1] =
Expr.FunctionCall1(param1, self: FunctionDef[A, B1])

Expand Down Expand Up @@ -247,6 +257,7 @@ trait ExprModule extends NewtypesModule with FeaturesModule with OpsModule {
}

object FunctionDef {

//math functions
val Abs = FunctionDef[Double, Double](FunctionName("abs"))
val Acos = FunctionDef[Double, Double](FunctionName("acos"))
Expand All @@ -256,27 +267,27 @@ trait ExprModule extends NewtypesModule with FeaturesModule with OpsModule {
val Cos = FunctionDef[Double, Double](FunctionName("cos"))
val Exp = FunctionDef[Double, Double](FunctionName("exp"))
val Floor = FunctionDef[Double, Double](FunctionName("floor"))
//val Log = FunctionDef[Double, Double](FunctionName("log")) //not part of SQL 2011 spec
val Ln = FunctionDef[Double, Double](FunctionName("ln"))
val Log = FunctionDef[(Double, Double), Double](FunctionName("log"))
val Mod = FunctionDef[(Double, Double), Double](FunctionName("mod"))
val Power = FunctionDef[(Double, Double), Double](FunctionName("power"))
val Round = FunctionDef[(Double, Int), Double](FunctionName("round"))
val Sign = FunctionDef[Double, Double](FunctionName("sign"))
val Sign = FunctionDef[Double, Int](FunctionName("sign"))
val Sin = FunctionDef[Double, Double](FunctionName("sin"))
val Sqrt = FunctionDef[Double, Double](FunctionName("sqrt"))
val Tan = FunctionDef[Double, Double](FunctionName("tan"))
val WidthBucket = FunctionDef[(Double, Double, Double, Int), Int](FunctionName("width bucket"))
val WidthBucket = FunctionDef[(Double, Double, Double, Int), Int](FunctionName("width_bucket"))

//string functions
val Ascii = FunctionDef[String, Int](FunctionName("ascii"))
val CharLength = FunctionDef[String, Int](FunctionName("character length"))
val CharLength = FunctionDef[String, Int](FunctionName("character_length"))
val Concat = FunctionDef[(String, String), String](FunctionName("concat"))
val Lower = FunctionDef[String, String](FunctionName("lower"))
val Ltrim = FunctionDef[String, String](FunctionName("ltrim"))
val OctetLength = FunctionDef[String, Int](FunctionName("octet length"))
val OctetLength = FunctionDef[String, Int](FunctionName("octet_length"))
val Overlay = FunctionDef[(String, String, Int, Option[Int]), String](FunctionName("overlay"))
val Position = FunctionDef[(String, String), Int](FunctionName("position"))
val Replace = FunctionDef[(String, String), String](FunctionName("replace"))
val Replace = FunctionDef[(String, String, String), String](FunctionName("replace"))
val Rtrim = FunctionDef[String, String](FunctionName("rtrim"))
val Substring = FunctionDef[(String, Int, Option[Int]), String](FunctionName("substring"))
//TODO substring regex
Expand Down
3 changes: 3 additions & 0 deletions core/jvm/src/main/scala/zio/sql/ops.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ trait OpsModule extends TypeTagModule {
case object NotEqual extends RelationalOp {
override val symbol: String = "<>"
}
case object Like extends RelationalOp {
override val symbol: String = "like"
}
}

}
4 changes: 3 additions & 1 deletion core/jvm/src/test/scala/zio/sql/GroupByHavingSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ object GroupByHavingSpec extends DefaultRunnableSpec {

object AggregatedProductSchema {
val sqldsl = new Sql {
override def renderRead(read: this.Read[_]): String = ???
override def renderDelete(delete: this.Delete[_]): String = ???
override def renderRead(read: this.Read[_]): String = ???
override def renderUpdate(update: Update[_]): String = ???
}
import sqldsl.ColumnSet._
import sqldsl.AggregationDef._
Expand Down
4 changes: 4 additions & 0 deletions core/jvm/src/test/scala/zio/sql/LogicalOpsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class LogicalOpsSpec extends DefaultRunnableSpec {
test("not works on boolean column") {
val selectNotDeleted = selectAll.where(deleted.not)
assert(selectNotDeleted)(anything)
},
test("like works on a string column") {
val query = selectAll.where(name like "%")
assert(query)(anything)
}
)
}
4 changes: 3 additions & 1 deletion core/jvm/src/test/scala/zio/sql/ProductSchema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package zio.sql

object ProductSchema {
val sql = new Sql {
override def renderRead(read: this.Read[_]): String = ???
override def renderDelete(delete: this.Delete[_]): String = ???
override def renderRead(read: this.Read[_]): String = ???
override def renderUpdate(update: this.Update[_]): String = ???
}
import sql.ColumnSet._
import sql._
Expand Down
4 changes: 3 additions & 1 deletion core/jvm/src/test/scala/zio/sql/TestBasicSelectSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ object TestBasicSelect {
val userSql = new Sql { self =>
import self.ColumnSet._

override def renderRead(read: this.Read[_]): String = ???
override def renderDelete(delete: this.Delete[_]): String = ???
override def renderRead(read: this.Read[_]): String = ???
override def renderUpdate(update: this.Update[_]): String = ???

val userTable =
(string("user_id") ++ localDate("dob") ++ string("first_name") ++ string("last_name")).table("users")
Expand Down
5 changes: 4 additions & 1 deletion examples/src/main/scala/Example1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import zio.sql.Sql
object Example1 extends Sql {
import ColumnSet._

def renderRead(read: Example1.Read[_]): String = ???
def renderRead(read: this.Read[_]): String = ???
def renderDelete(delete: this.Delete[_]): String = ???

def renderUpdate(update: Example1.Update[_]): String = ???

val columnSet = int("age") ++ string("name")

Expand Down
Loading

0 comments on commit bf5b426

Please sign in to comment.