Comments (3)
enum class BitOperationType(val op: String) {
AND("&"),
OR("|"),
XOR("^"),
LEFT_SHIFT("<<"),
RIGHT_SHIFT(">>");
override fun toString(): String {
return op;
}
}
data class BitOperationExpression(
val type: BitOperationType,
val left: ScalarExpression<Long>,
val right: ScalarExpression<Long>,
override val sqlType: SqlType<Long>,
override val isLeafNode: Boolean = false,
override val extraProperties: Map<String, Any> = emptyMap()
) : ScalarExpression<Long>()
infix fun ColumnDeclaring<Long>.and(expr: ColumnDeclaring<Long>): BitOperationExpression {
return BitOperationExpression(BitOperationType.AND, asExpression(), expr.asExpression(), LongSqlType)
}
infix fun ColumnDeclaring<Long>.or(expr: ColumnDeclaring<Long>): BitOperationExpression {
return BitOperationExpression(BitOperationType.OR, asExpression(), expr.asExpression(), LongSqlType)
}
infix fun ColumnDeclaring<Long>.xor(expr: ColumnDeclaring<Long>): BitOperationExpression {
return BitOperationExpression(BitOperationType.XOR, asExpression(), expr.asExpression(), LongSqlType)
}
infix fun ColumnDeclaring<Long>.shl(bitCount: Int): BitOperationExpression {
return BitOperationExpression(BitOperationType.LEFT_SHIFT, asExpression(), ArgumentExpression(bitCount.toLong(), LongSqlType), LongSqlType)
}
infix fun ColumnDeclaring<Long>.shr(bitCount: Int): BitOperationExpression {
return BitOperationExpression(BitOperationType.RIGHT_SHIFT, asExpression(), ArgumentExpression(bitCount.toLong(), LongSqlType), LongSqlType)
}
fun ColumnDeclaring<Long>.inv(): BitOperationExpression {
return this xor ArgumentExpression(0xFFFFFFFFFFFFFFFFUL.toLong(), LongSqlType)
}
class CustomSqlFormatter (
database: Database, beautifySql: Boolean, indentSize: Int
) : MySqlFormatter(database, beautifySql, indentSize) {
override fun visitUnknown(expr: SqlExpression): SqlExpression {
if (expr is BitOperationExpression) {
if (expr.left.removeBrackets) {
visit(expr.left)
} else {
write("(")
visit(expr.left)
removeLastBlank()
write(") ")
}
writeKeyword("${expr.type} ")
if (expr.right.removeBrackets) {
visit(expr.right)
} else {
write("(")
visit(expr.right)
removeLastBlank()
write(") ")
}
return expr
}
return super.visitUnknown(expr)
}
}
fun main() {
val database = Database.connect(
url = "jdbc:mysql://localhost:3306/ktorm-example",
user = "root",
dialect = object : MySqlDialect() {
override fun createSqlFormatter(database: Database, beautifySql: Boolean, indentSize: Int): SqlFormatter {
return CustomSqlFormatter(database, beautifySql, indentSize)
}
}
)
// Use the database instance to perform your operations...
}
from ktorm.
I tried custom ColumnDeclaring, but the BinaryExpression first parament only accpet BinaryExpressionType, which is enum and do not has BinaryExpressionType.BitAnd, so it seems impossible to support bitAnd, unless official update the ktorm lib
infix fun ColumnDeclaring<Int>.bitAnd(value :Int):BinaryExpression<Int>{
return BinaryExpression(
BinaryExpressionType.AND,
asExpression(),
wrapArgument(value),
IntSqlType
)
}
from ktorm.
so I solved this problem
#573
from ktorm.
Related Issues (20)
- 适配 solon框架 HOT 1
- Union功能存在问题? HOT 2
- 关于列绑定,能不能先references再transform?
- 🧐为什么不添加支持分页的函数呢 HOT 2
- Oracle Timestamp support
- Database#exceptionTranslator should return a nullable throwable
- 4.0版本使用KSP生成实体类运行出错 HOT 8
- ksp column converter in version 4.0.0 disappeared HOT 1
- Ktorm 别名机制似乎有问题 HOT 2
- [Feature Request]: Support OffsetDateTime for Postgresql
- [Feature Request]: KSP Table Annotation Support Specify super class for the table generated HOT 1
- Relaxing BaseTable related visibility constraints
- Postgres how to use TextArray's Contains method? HOT 1
- 使用实体查询,框架会拼接字段名称为【表别名_字段】而遭到 ColumnNameChecker 字段名称过长拦截 HOT 6
- Document DDL HOT 2
- H2: escaped column names do not work HOT 3
- Please add support for ILIKE HOT 2
- 4.0+版本使用KSP生成实体类不兼容无符号整数类型 HOT 5
- KSP: Keep entity's deprecation annotations in generated table definitions.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ktorm.