Skip to content

Commit

Permalink
add some more where constraint operators + overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredh159 committed Jun 28, 2022
1 parent 1f91eb6 commit 31f87c8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/DuetSQL/SQL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ public enum SQL {
\(statement.query)
"""

if LOG_SQL {
print("\n```SQL\n\(insertPrepareSql)\n```")
}

await prepared.set(name, forKey: key)
_ = try await db.raw("\(raw: insertPrepareSql)").all().get()
}
Expand Down
35 changes: 35 additions & 0 deletions Sources/DuetSQL/WhereConstraint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,34 @@ public func == <M: Model>(
.equals(lhs, .uuid(rhs))
}

public func == <M: Model>(
lhs: M.ColumnName,
rhs: PostgresEnum
) -> SQL.WhereConstraint<M> {
.equals(lhs, .enum(rhs))
}

public func != <M: Model>(
lhs: M.ColumnName,
rhs: Postgres.Data
) -> SQL.WhereConstraint<M> {
.not(.equals(lhs, rhs))
}

public func != <M: Model>(
lhs: M.ColumnName,
rhs: UUIDStringable
) -> SQL.WhereConstraint<M> {
.not(.equals(lhs, .uuid(rhs)))
}

public func != <M: Model>(
lhs: M.ColumnName,
rhs: PostgresEnum
) -> SQL.WhereConstraint<M> {
.not(.equals(lhs, .enum(rhs)))
}

infix operator |=|

public func |=| <M: Model>(
Expand Down Expand Up @@ -244,6 +272,13 @@ public func |!=| <M: Model>(
.not(.in(lhs, rhs))
}

public func |!=| <M: Model>(
lhs: M.ColumnName,
rhs: [PostgresEnum]
) -> SQL.WhereConstraint<M> {
.not(.in(lhs, rhs.map { .enum($0) }))
}

infix operator <>

public func <> <M: Model>(
Expand Down

0 comments on commit 31f87c8

Please sign in to comment.