Skip to content

Commit

Permalink
规范代码
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzhang7982 committed Sep 17, 2023
1 parent 3086953 commit d7fdd7e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
20 changes: 10 additions & 10 deletions core/src/main/scala/easysql/dsl/Clause.scala
Expand Up @@ -22,22 +22,22 @@ def col[T <: SqlDataType](text: String): DynamicExpr[T] =
def caseWhen[T <: SqlDataType](branches: CaseBranch[T]*): CaseExpr[T] =
CaseExpr(branches.toList, NullExpr)

def exists[T <: SqlDataType](query: Select[Tuple1[T], _]): FuncExpr[Boolean] =
def exists[T <: SqlDataType](query: Select[Tuple1[T], ?]): FuncExpr[Boolean] =
FuncExpr("EXISTS", List(SubQueryExpr(query)))

def notExists[T <: SqlDataType](query: Select[Tuple1[T], _]): FuncExpr[Boolean] =
def notExists[T <: SqlDataType](query: Select[Tuple1[T], ?]): FuncExpr[Boolean] =
FuncExpr("NOT EXISTS", List(SubQueryExpr(query)))

def all[T <: SqlDataType](query: Select[Tuple1[T], _]): FuncExpr[T] =
def all[T <: SqlDataType](query: Select[Tuple1[T], ?]): FuncExpr[T] =
FuncExpr("ALL", List(SubQueryExpr(query)))

def any[T <: SqlDataType](query: Select[Tuple1[T], _]): FuncExpr[T] =
def any[T <: SqlDataType](query: Select[Tuple1[T], ?]): FuncExpr[T] =
FuncExpr("ANY", List(SubQueryExpr(query)))

def some[T <: SqlDataType](query: Select[Tuple1[T], _]): FuncExpr[T] =
def some[T <: SqlDataType](query: Select[Tuple1[T], ?]): FuncExpr[T] =
FuncExpr("SOME", List(SubQueryExpr(query)))

def cast[T <: SqlDataType](expr: Expr[_], castType: String): CastExpr[T] =
def cast[T <: SqlDataType](expr: Expr[?], castType: String): CastExpr[T] =
CastExpr(expr, castType)

def table(name: String): TableSchema[Nothing] =
Expand All @@ -63,14 +63,14 @@ extension (n: Int) {
transparent inline def asTable[T <: Product]: Any =
tableInfo[T]

extension [T <: SqlDataType] (expr: ColumnExpr[T, _] | DynamicExpr[T]) {
infix def toExpr[R <: UpdateType[T]](value: Expr[R]): (ColumnExpr[T, _] | DynamicExpr[T], Expr[R]) =
extension [T <: SqlDataType] (expr: ColumnExpr[T, ?] | DynamicExpr[T]) {
infix def toExpr[R <: UpdateType[T]](value: Expr[R]): (ColumnExpr[T, ?] | DynamicExpr[T], Expr[R]) =
(expr, value)

infix def to[R <: UpdateType[T]](value: R): (ColumnExpr[T, _] | DynamicExpr[T], Expr[R]) =
infix def to[R <: UpdateType[T]](value: R): (ColumnExpr[T, ?] | DynamicExpr[T], Expr[R]) =
(expr, LiteralExpr(value))

infix def toOption[R <: UpdateType[T]](value: Option[R]): (ColumnExpr[T, _] | DynamicExpr[T], Expr[_]) = {
infix def toOption[R <: UpdateType[T]](value: Option[R]): (ColumnExpr[T, ?] | DynamicExpr[T], Expr[?]) = {
val updateExpr = value match {
case None => NullExpr
case Some(value) => LiteralExpr(value)
Expand Down
9 changes: 2 additions & 7 deletions core/src/main/scala/easysql/macros/TableMacroImpl.scala
Expand Up @@ -115,11 +115,7 @@ def identNamesMacro[T](using q: Quotes, t: Type[T]): Expr[List[String]] = {
import q.reflect.*

val sym = TypeTree.of[T].symbol
val fields = sym.declaredFields.map { f =>
var fieldName = f.name

Expr(fieldName)
}
val fields = sym.declaredFields.map(f => Expr(f.name))

Expr.ofList(fields)
}
Expand All @@ -129,7 +125,6 @@ def tableInfoMacro[T <: Product](using q: Quotes, t: Type[T]): Expr[Any] = {

val sym = TypeTree.of[T].symbol
val fields = sym.declaredFields
var typ = TypeRepr.of[TableSchema[T]]
val tableName = fetchTableNameMacro[T]
val typs = fields.map { field =>
val singletonName = Singleton(Expr(field.name).asTerm)
Expand Down Expand Up @@ -186,7 +181,7 @@ def tableInfoMacro[T <: Product](using q: Quotes, t: Type[T]): Expr[Any] = {
}
}

var refinement = Refinement(typ, typs.head._1, typs.head._2)
var refinement = Refinement(TypeRepr.of[TableSchema[T]], typs.head._1, typs.head._2)
for (i <- 1 until typs.size) {
refinement = Refinement(refinement, typs(i)._1, typs(i)._2)
}
Expand Down

0 comments on commit d7fdd7e

Please sign in to comment.