Skip to content

Commit

Permalink
Action sbt scalafmtAll
Browse files Browse the repository at this point in the history
  • Loading branch information
takapi327 committed Feb 16, 2025
1 parent 616b87c commit 10c2b37
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 46 deletions.
24 changes: 20 additions & 4 deletions module/ldbc-schema/src/main/scala/ldbc/schema/Table.scala
Original file line number Diff line number Diff line change
Expand Up @@ -427,17 +427,29 @@ object Table:

inline def float[A <: Float | Option[Float]](alias: String): Int => DataTypeColumn.NumericColumn[A] =
${
namedDoubleColumnImpl[A]('{ Some(alias) }, '{ (accuracy: Int) => CFloat(accuracy, isOptional[A]) }, '{ isOptional[A] })
namedDoubleColumnImpl[A](
'{ Some(alias) },
'{ (accuracy: Int) => CFloat(accuracy, isOptional[A]) },
'{ isOptional[A] }
)
}

inline def double[A <: Double | Option[Double]](alias: String): Int => DataTypeColumn.NumericColumn[A] =
${
namedDoubleColumnImpl[A]('{ Some(alias) }, '{ (accuracy: Int) => CFloat(accuracy, isOptional[A]) }, '{ isOptional[A] })
namedDoubleColumnImpl[A](
'{ Some(alias) },
'{ (accuracy: Int) => CFloat(accuracy, isOptional[A]) },
'{ isOptional[A] }
)
}

inline def char[A <: String | Option[String]](alias: String): Int => DataTypeColumn.StringColumn[A] =
${
namedStringLengthColumnImpl[A]('{ Some(alias) }, '{ (length: Int) => CChar(length, isOptional[A]) }, '{ isOptional[A] })
namedStringLengthColumnImpl[A](
'{ Some(alias) },
'{ (length: Int) => CChar(length, isOptional[A]) },
'{ isOptional[A] }
)
}

inline def varchar[A <: String | Option[String]](alias: String): Int => DataTypeColumn.StringColumn[A] =
Expand All @@ -451,7 +463,11 @@ object Table:

inline def binary[A <: Array[Byte] | Option[Array[Byte]]](alias: String): Int => DataTypeColumn.StringColumn[A] =
${
namedStringLengthColumnImpl[A]('{ Some(alias) }, '{ (length: Int) => Binary(length, isOptional[A]) }, '{ isOptional[A] })
namedStringLengthColumnImpl[A](
'{ Some(alias) },
'{ (length: Int) => Binary(length, isOptional[A]) },
'{ isOptional[A] }
)
}

inline def varbinary[A <: Array[Byte] | Option[Array[Byte]]](alias: String): Int => DataTypeColumn.StringColumn[A] =
Expand Down
14 changes: 7 additions & 7 deletions module/ldbc-schema/src/main/scala/ldbc/schema/TableQuery.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ case class TableQueryImpl[A <: Table[?]](
.asInstanceOf[AbstractTableQuery[A, Table.Opt[AbstractTableQuery.Extract[A]]]]

private def createStatement(ifNotExists: Boolean): Schema.DDL =
val columns = column.list.map(_.statement).mkString(",\n ")
val keys = table.keys.map(_.queryString).mkString(",\n ")
val statement = s"CREATE TABLE ${ if (ifNotExists) "IF NOT EXISTS " else "" }`$name` (\n $columns,\n $keys\n)"
val columns = column.list.map(_.statement).mkString(",\n ")
val keys = table.keys.map(_.queryString).mkString(",\n ")
val statement = s"CREATE TABLE ${ if ifNotExists then "IF NOT EXISTS " else "" }`$name` (\n $columns,\n $keys\n)"
Schema.DDL(statement)

override def schema: Schema = Schema(
create = createStatement(false),
create = createStatement(false),
createIfNotExists = createStatement(true),
drop = Schema.DDL(s"DROP TABLE `$name`"),
dropIfExists = Schema.DDL(s"DROP TABLE IF EXISTS `$name`"),
truncate = Schema.DDL(s"TRUNCATE TABLE `$name`")
drop = Schema.DDL(s"DROP TABLE `$name`"),
dropIfExists = Schema.DDL(s"DROP TABLE IF EXISTS `$name`"),
truncate = Schema.DDL(s"TRUNCATE TABLE `$name`")
)

private[ldbc] case class TableQueryOpt[A, O](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ package object syntax:
connection =>
for
statement <- connection.createStatement()
_ <- ddl.statements.map(statement.addBatch).sequence
result <- statement.executeBatch()
_ <- ddl.statements.map(statement.addBatch).sequence
result <- statement.executeBatch()
yield result
)

Expand Down
46 changes: 23 additions & 23 deletions module/ldbc-statement/src/main/scala/ldbc/statement/Schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,54 +47,54 @@ trait Schema:
* DDL to truncate a table.
*/
def truncate: Schema.DDL

def ++(other: Schema): Schema

object Schema:

trait DDL:

def statements: List[String]

def ++(other: DDL): DDL

object DDL:

private case class Impl(statements: List[String]) extends DDL:

override def ++(other: DDL): DDL = Impl(statements ++ other.statements)

def apply(statement: String): DDL = Impl(List(statement))

case class Impl(
create: Schema.DDL,
create: Schema.DDL,
createIfNotExists: Schema.DDL,
drop: Schema.DDL,
dropIfExists: Schema.DDL,
truncate: Schema.DDL
drop: Schema.DDL,
dropIfExists: Schema.DDL,
truncate: Schema.DDL
) extends Schema:

override def ++(other: Schema): Schema =
this.copy(
create = this.create ++ other.create,
create = this.create ++ other.create,
createIfNotExists = this.createIfNotExists ++ other.createIfNotExists,
drop = this.drop ++ other.drop,
dropIfExists = this.dropIfExists ++ other.dropIfExists,
truncate = this.truncate ++ other.truncate
drop = this.drop ++ other.drop,
dropIfExists = this.dropIfExists ++ other.dropIfExists,
truncate = this.truncate ++ other.truncate
)

def apply(
create: Schema.DDL,
create: Schema.DDL,
createIfNotExists: Schema.DDL,
drop: Schema.DDL,
dropIfExists: Schema.DDL,
truncate: Schema.DDL
drop: Schema.DDL,
dropIfExists: Schema.DDL,
truncate: Schema.DDL
): Schema = Impl(create, createIfNotExists, drop, dropIfExists, truncate)

def empty: Schema = Impl(
create = DDL(""),
create = DDL(""),
createIfNotExists = DDL(""),
drop = DDL(""),
dropIfExists = DDL(""),
truncate = DDL("")
drop = DDL(""),
dropIfExists = DDL(""),
truncate = DDL("")
)
22 changes: 12 additions & 10 deletions tests/src/test/scala/ldbc/tests/DDLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import munit.*

import ldbc.sql.Connection

import ldbc.schema.{Table, TableQuery, Key}
import ldbc.schema.{ Key, Table, TableQuery }
import ldbc.schema.syntax.io.*

import ldbc.connector.SSL
Expand Down Expand Up @@ -58,9 +58,9 @@ trait DDLTest extends CatsEffectSuite:
)

class UserTable extends Table[User]("user"):
def id: Column[Long] = bigint().autoIncrement
def name: Column[String] = varchar(255)
def age: Column[Option[Int]] = int()
def id: Column[Long] = bigint().autoIncrement
def name: Column[String] = varchar(255)
def age: Column[Option[Int]] = int()

override def keys: List[Key] = List(PRIMARY_KEY(id))

Expand All @@ -72,12 +72,14 @@ trait DDLTest extends CatsEffectSuite:
connection
.use { conn =>
// The following implementation is used to test the possibility of multiple executions.
DBIO.sequence(
userTable.schema.create,
userTable.schema.createIfNotExists,
userTable.schema.dropIfExists,
userTable.schema.create
).commit(conn) *> IO.unit
DBIO
.sequence(
userTable.schema.create,
userTable.schema.createIfNotExists,
userTable.schema.dropIfExists,
userTable.schema.create
)
.commit(conn) *> IO.unit
}
.unsafeRunSync()

Expand Down

0 comments on commit 10c2b37

Please sign in to comment.