Skip to content

Commit

Permalink
Integrating Doobie Support (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
deusaquilus authored May 9, 2022
1 parent ce71644 commit f3dd8cb
Show file tree
Hide file tree
Showing 15 changed files with 815 additions and 83 deletions.
16 changes: 15 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ lazy val sqlTestModules = Seq[sbt.ClasspathDep[sbt.ProjectReference]](
)

lazy val dbModules = Seq[sbt.ClasspathDep[sbt.ProjectReference]](
`quill-jdbc`, `quill-zio`, `quill-jdbc-zio`, `quill-caliban`
`quill-jdbc`, `quill-doobie`, `quill-zio`, `quill-jdbc-zio`, `quill-caliban`
)

lazy val jasyncModules = Seq[sbt.ClasspathDep[sbt.ProjectReference]](
Expand Down Expand Up @@ -169,6 +169,20 @@ lazy val `quill-jdbc` =
.settings(jdbcTestingSettings: _*)
.dependsOn(`quill-sql` % "compile->compile;test->test")

ThisBuild / libraryDependencySchemes += "org.typelevel" %% "cats-effect" % "always"
lazy val `quill-doobie` =
(project in file("quill-doobie"))
.settings(commonSettings: _*)
.settings(releaseSettings: _*)
.settings(jdbcTestingSettings: _*)
.settings(
libraryDependencies ++= Seq(
"org.tpolecat" %% "doobie-core" % "1.0.0-RC2",
"org.tpolecat" %% "doobie-postgres" % "1.0.0-RC2" % Test
)
)
.dependsOn(`quill-jdbc` % "compile->compile;test->test")

lazy val `quill-jasync` =
(project in file("quill-jasync"))
.settings(commonSettings: _*)
Expand Down
2 changes: 1 addition & 1 deletion build/setup_bigdata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ time docker-compose up -d cassandra orientdb
# setup cassandra in docker
send_script cassandra $CASSANDRA_SCRIPT cassandra-schema.cql
send_script cassandra ./build/setup_db_scripts.sh setup_db_scripts.sh
time docker-compose exec -T cassandra bash -c ". setup_db_scripts.sh && setup_cassandra cassandra-schema.cql 127.0.0.1"
time docker-compose exec -T cassandra bash -c ". setup_db_scripts.sh && setup_cassandra 127.0.0.1 cassandra-schema.cql"

echo "Databases are ready!"
8 changes: 4 additions & 4 deletions build/setup_databases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ echo "### Sourcing DB Scripts ###"

# run setup scripts for local databases
echo "### Running Setup for sqlite ###"
time setup_sqlite $SQLITE_SCRIPT 127.0.0.1
time setup_sqlite 127.0.0.1
echo "### Running Setup for mysql ###"
time setup_mysql $MYSQL_SCRIPT 127.0.0.1 13306
time setup_mysql 127.0.0.1 13306
echo "### Running Setup for postgres ###"
time setup_postgres $POSTGRES_SCRIPT 127.0.0.1 15432
time setup_postgres 127.0.0.1 15432

echo "### Running Setup for sqlserver ###"
# setup sqlserver in docker
send_script sqlserver $SQL_SERVER_SCRIPT sqlserver-schema.sql
send_script sqlserver ./build/setup_db_scripts.sh setup_db_scripts.sh
time docker-compose exec -T sqlserver bash -c ". setup_db_scripts.sh && setup_sqlserver sqlserver-schema.sql 127.0.0.1"
time docker-compose exec -T sqlserver bash -c ". setup_db_scripts.sh && setup_sqlserver 127.0.0.1 sqlserver-schema.sql"

# Can't do absolute paths here so need to do relative
mkdir sqlline/
Expand Down
62 changes: 34 additions & 28 deletions build/setup_db_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export SQLITE_SCRIPT=quill-jdbc/src/test/resources/sql/sqlite-schema.sql
export MYSQL_SCRIPT=quill-sql/src/test/sql/mysql-schema.sql
export POSTGRES_SCRIPT=quill-sql/src/test/sql/postgres-schema.sql
export POSTGRES_DOOBIE_SCRIPT=quill-sql/src/test/sql/postgres-doobie-schema.sql
export SQL_SERVER_SCRIPT=quill-sql/src/test/sql/sqlserver-schema.sql
export ORACLE_SCRIPT=quill-sql/src/test/sql/oracle-schema.sql
export CASSANDRA_SCRIPT=quill-cassandra/src/test/cql/cassandra-schema.cql
Expand All @@ -24,22 +25,22 @@ function setup_sqlite() {
echo "Removing Previous sqlite DB File (if any)"
rm -f $DB_FILE
echo "Creating sqlite DB File"
echo "(with the $1 script)"
sqlite3 $DB_FILE < $1
echo "(with the $SQLITE_SCRIPT script)"
sqlite3 $DB_FILE < $SQLITE_SCRIPT
echo "Setting permissions on sqlite DB File"
chmod a+rw $DB_FILE

# # DB File in quill-jdbc-monix
# DB_FILE=quill-jdbc-monix/quill_test.db
# rm -f $DB_FILE
# sqlite3 $DB_FILE < $1
# chmod a+rw $DB_FILE
# # DB File in quill-jdbc-monix
# DB_FILE=quill-jdbc-monix/quill_test.db
# rm -f $DB_FILE
# sqlite3 $DB_FILE < $SQLITE_SCRIPT
# chmod a+rw $DB_FILE

echo "Sqlite ready!"
}

function setup_mysql() {
port=$3
port=$2
password=''
if [ -z "$port" ]; then
echo "MySQL Port not defined. Setting to default: 3306 "
Expand All @@ -48,7 +49,7 @@ function setup_mysql() {
echo "MySQL Port specified as $port"
fi

connection=$2
connection=$1
MYSQL_ROOT_PASSWORD=root

echo "Waiting for MySql"
Expand All @@ -68,7 +69,7 @@ function setup_mysql() {
echo "MySql: Create quill_test"
mysql --protocol=tcp --host=$connection --password="$MYSQL_ROOT_PASSWORD" --port=$port -u root -e "CREATE DATABASE quill_test;"
echo "MySql: Write Schema to quill_test"
mysql --protocol=tcp --host=$connection --password="$MYSQL_ROOT_PASSWORD" --port=$port -u root quill_test < $1
mysql --protocol=tcp --host=$connection --password="$MYSQL_ROOT_PASSWORD" --port=$port -u root quill_test < $MYSQL_SCRIPT
echo "MySql: Create finagle user"
mysql --protocol=tcp --host=$connection --password="$MYSQL_ROOT_PASSWORD" --port=$port -u root -e "CREATE USER 'finagle'@'%' IDENTIFIED BY 'finagle';"
echo "MySql: Grant finagle user"
Expand All @@ -78,61 +79,66 @@ function setup_mysql() {
}

function setup_postgres() {
port=$3
port=$2
host=$1
if [ -z "$port" ]; then
echo "Postgres Port not defined. Setting to default: 5432"
port="5432"
else
echo "Postgres Port specified as $port"
fi
echo "Waiting for Postgres"
until psql --host $2 --port $port --username postgres -c "select 1" &> /dev/null; do
echo "## Tapping Postgres Connection> psql --host $2 --port $port --username postgres -c 'select 1'"
psql --host $2 --port $port --username postgres -c "select 1" || true
until psql --host $host --port $port --username postgres -c "select 1" &> /dev/null; do
echo "## Tapping Postgres Connection> psql --host $host --port $port --username postgres -c 'select 1'"
psql --host $host --port $port --username postgres -c "select 1" || true
sleep 5;
done
echo "Connected to Postgres"

echo "Postgres: Create codegen_test"
psql --host $2 --port $port -U postgres -c "CREATE DATABASE codegen_test"
psql --host $host --port $port -U postgres -c "CREATE DATABASE codegen_test"
echo "Postgres: Create quill_test"
psql --host $2 --port $port -U postgres -c "CREATE DATABASE quill_test"
psql --host $host --port $port -U postgres -c "CREATE DATABASE quill_test"
echo "Postgres: Write Schema to quill_test"
psql --host $2 --port $port -U postgres -d quill_test -a -q -f $1
psql --host $host --port $port -U postgres -d quill_test -a -q -f $POSTGRES_SCRIPT
echo "Postgres: Create doobie_test"
psql --host $host --port $port -U postgres -c "CREATE DATABASE doobie_test"
echo "Postgres: Write Schema to doobie_test"
psql --host $host --port $port -U postgres -d doobie_test -a -q -f $POSTGRES_DOOBIE_SCRIPT
}

function setup_cassandra() {
host=$(get_host $2)
host=$(get_host $1)
echo "Waiting for Cassandra"
until cqlsh $2 -e "describe cluster" &> /dev/null; do
until cqlsh $1 -e "describe cluster" &> /dev/null; do
sleep 5;
done
echo "Connected to Cassandra"

cqlsh $2 -f $1
cqlsh $1 -f $2
}

function setup_sqlserver() {
host=$(get_host $2)
host=$(get_host $1)
echo "Waiting for SqlServer"
until /opt/mssql-tools/bin/sqlcmd -S $2 -U SA -P "QuillRocks!" -Q "select 1" &> /dev/null; do
until /opt/mssql-tools/bin/sqlcmd -S $1 -U SA -P "QuillRocks!" -Q "select 1" &> /dev/null; do
sleep 5;
done
echo "Connected to SqlServer"

/opt/mssql-tools/bin/sqlcmd -S $2 -U SA -P "QuillRocks!" -Q "CREATE DATABASE codegen_test"
/opt/mssql-tools/bin/sqlcmd -S $2 -U SA -P "QuillRocks!" -Q "CREATE DATABASE alpha"
/opt/mssql-tools/bin/sqlcmd -S $2 -U SA -P "QuillRocks!" -Q "CREATE DATABASE bravo"
/opt/mssql-tools/bin/sqlcmd -S $2 -U SA -P "QuillRocks!" -Q "CREATE DATABASE quill_test"
/opt/mssql-tools/bin/sqlcmd -S $2 -U SA -P "QuillRocks!" -d quill_test -i $1
/opt/mssql-tools/bin/sqlcmd -S $1 -U SA -P "QuillRocks!" -Q "CREATE DATABASE codegen_test"
/opt/mssql-tools/bin/sqlcmd -S $1 -U SA -P "QuillRocks!" -Q "CREATE DATABASE alpha"
/opt/mssql-tools/bin/sqlcmd -S $1 -U SA -P "QuillRocks!" -Q "CREATE DATABASE bravo"
/opt/mssql-tools/bin/sqlcmd -S $1 -U SA -P "QuillRocks!" -Q "CREATE DATABASE quill_test"
/opt/mssql-tools/bin/sqlcmd -S $1 -U SA -P "QuillRocks!" -d quill_test -i $2
}

# Do a simple necat poll to make sure the oracle database is ready.
# All internal database creation and schema setup scripts are handled
# by the container and docker-compose steps.

function setup_oracle() {
while ! nc -z $2 1521; do
while ! nc -z $1 1521; do
echo "Waiting for Oracle"
sleep 2;
done;
Expand Down
13 changes: 7 additions & 6 deletions build/setup_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ set -e
. /app/build/setup_db_scripts.sh


time setup_mysql $MYSQL_SCRIPT mysql
time setup_postgres $POSTGRES_SCRIPT postgres
time setup_cassandra $CASSANDRA_SCRIPT cassandra
time setup_sqlserver $SQL_SERVER_SCRIPT sqlserver
time setup_oracle $ORACLE_SCRIPT oracle
time setup_mysql mysql
time setup_postgres postgres
time setup_cassandra cassandra $CASSANDRA_SCRIPT
# SQL Server needs to be passed different script paths based on environment. Therefore it has a 2nd arg.
time setup_sqlserver sqlserver $SQL_SERVER_SCRIPT
time setup_oracle oracle

# TODO Move this back up to the top. This is failing for now but want mysql to succeed
time setup_sqlite $SQLITE_SCRIPT
time setup_sqlite

echo "Databases are ready!"
4 changes: 2 additions & 2 deletions build/setup_mysql_postgres_databases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ docker ps
. build/setup_db_scripts.sh

# run setup scripts for local databases
time setup_mysql $MYSQL_SCRIPT 127.0.0.1 13306
time setup_postgres $POSTGRES_SCRIPT 127.0.0.1 15432
time setup_mysql 127.0.0.1 13306
time setup_postgres 127.0.0.1 15432

echo "Postgres and MySQL Databases are ready!"
32 changes: 32 additions & 0 deletions quill-doobie/src/main/scala/io/getquill/doobie/DoobieContext.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.getquill.doobie

import io.getquill._
import io.getquill.context.jdbc._

object DoobieContext {

class H2[N <: NamingStrategy](val naming: N)
extends DoobieContextBase[H2Dialect, N]
with H2JdbcTypes[N]

class MySQL[N <: NamingStrategy](val naming: N)
extends DoobieContextBase[MySQLDialect, N]
with MysqlJdbcTypes[N]

class Oracle[N <: NamingStrategy](val naming: N)
extends DoobieContextBase[OracleDialect, N]
with OracleJdbcTypes[N]

class Postgres[N <: NamingStrategy](val naming: N)
extends DoobieContextBase[PostgresDialect, N]
with PostgresJdbcTypes[N]

class SQLite[N <: NamingStrategy](val naming: N)
extends DoobieContextBase[SqliteDialect, N]
with SqliteJdbcTypes[N]

class SQLServer[N <: NamingStrategy](val naming: N)
extends DoobieContextBase[SQLServerDialect, N]
with SqlServerJdbcTypes[N]

}
Loading

0 comments on commit f3dd8cb

Please sign in to comment.