Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions ktorm-core/src/main/kotlin/org/ktorm/dsl/Operators.kt
Original file line number Diff line number Diff line change
Expand Up @@ -696,3 +696,49 @@ public fun ColumnDeclaring<Boolean>.toInt(): CastingExpression<Int> {
public fun <T : Any> ColumnDeclaring<*>.cast(sqlType: SqlType<T>): CastingExpression<T> {
return CastingExpression(asExpression(), sqlType)
}

// --------- bit And ------------

/**
* And operator, translated to the `&` keyword in SQL.
*/
public infix fun ColumnDeclaring<Int>.bitAnd(expr: ColumnDeclaring<Int>): BinaryExpression<Int> {
return BinaryExpression(BinaryExpressionType.BIT_AND, asExpression(), expr.asExpression(), IntSqlType)
}

/**
* And operator, translated to the `&` keyword in SQL.
*/
public infix fun ColumnDeclaring<Int>.bitAnd(value: Int): BinaryExpression<Int> {
return this bitAnd wrapArgument(value)
}

/**
* And operator, translated to the `&` keyword in SQL.
*/
public infix fun Int.bitAnd(expr: ColumnDeclaring<Int>): BinaryExpression<Int> {
return expr.wrapArgument(this) bitAnd expr
}

// --------- bit Or ------------

/**
* And operator, translated to the `|` keyword in SQL.
*/
public infix fun ColumnDeclaring<Int>.bitOr(expr: ColumnDeclaring<Int>): BinaryExpression<Int> {
return BinaryExpression(BinaryExpressionType.BIT_AND, asExpression(), expr.asExpression(), IntSqlType)
}

/**
* And operator, translated to the `|` keyword in SQL.
*/
public infix fun ColumnDeclaring<Int>.bitOr(value: Int): BinaryExpression<Int> {
return this bitOr wrapArgument(value)
}

/**
* And operator, translated to the `|` keyword in SQL.
*/
public infix fun Int.bitOr(expr: ColumnDeclaring<Int>): BinaryExpression<Int> {
return expr.wrapArgument(this) bitOr expr
}
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,17 @@ public enum class BinaryExpressionType(private val value: String) {
/**
* Not-equal operator, translated to `<>` in SQL.
*/
NOT_EQUAL("<>");
NOT_EQUAL("<>"),

/**
* bit-and operator, translated to `&` in SQL.
*/
BIT_AND("&"),

/**
* bit-or operator, translated to `|` in SQL.
*/
BIT_OR("|");

override fun toString(): String {
return value
Expand Down
Loading