reposilite-playground / exposed-upsert Goto Github PK
View Code? Open in Web Editor NEWUpsert DSL extension for Exposed, Kotlin SQL framework
License: The Unlicense
Upsert DSL extension for Exposed, Kotlin SQL framework
License: The Unlicense
Stacktrace: https://pastebin.com/raw/XzKVWhuB
This is my upsert statement:
TileEntitiesTable.upsert(
conflictColumn = TileEntitiesTable.uuid,
insertBody = {
val location = tileEntity.location
it[uuid] = tileEntity.uuid
it[world] = tileEntity.location.world!!.uid
it[chunkX] = chunk.x
it[chunkZ] = chunk.z
it[x] = location.blockX
it[y] = location.blockY
it[z] = location.blockZ
it[yaw] = tileEntity.armorStand.location.yaw
it[type] = tileEntity.material.typeName
it[data] = ExposedBlob(tileEntity.getData())
},
updateBody = {
it[data] = ExposedBlob(tileEntity.getData())
}
)
The above upsert statement generates this sql:
INSERT INTO tileEntities (chunkX, chunkZ, "data", "type", uuid, world, x, y, yaw, z) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT("uuid") DO UPDATE SET "data"=EXCLUDED."data"
As you can see, the statement is invalid, there should be another question mark in the update statement after "data"=
This leads to an ArrayIndexOutOfBoundsException in CorePreparedStatement.java.
I fixed it in this commit: https://github.com/NichtStudioCode/exposed-upsert/commit/297be27e8ab2aad81c404676653f2d0320650271. This is obviously not a perfect solution, hence why I am not making a pull request.
Hi,
the "manual" installation releases link doesn't work,
probably should be https://repo.panda-lang.org/#/releases/net/dzikoysk/exposed-upsert
Do you think of releasing this to central maven repository?
a) repository link at bottom of page https://androidrepo.com/repo/dzikoysk-exposed-upsert is still broken
b)
if I have non DAO exposed Tables, is your upsert supposed to work also?
I have DSL defined tables (non IdTables)
abstract class BaseTable(name: String) : Table(name) {
val dtoModCount = long("dto_mod_count")
val dtoOptimisticLockId = long("dto_optimistic_lock_id")
val dtoCreationDate = timestamp("dto_creation_date")
val dtoCreationUser = varchar("dto_creation_user", VARCHAR_MEDIUM)
val dtoModDate = timestamp("dto_mod_date")
val dtoModUser = varchar("dto_mod_user", VARCHAR_MEDIUM)
}
object IssuesTable : BaseTable(name = "ISSUES") {
val key = varchar("key", VARCHAR_SMALL)
val project = varchar("project", VARCHAR_SMALL)
...
override val primaryKey = PrimaryKey(key, name = "PK_Issue_key")
private fun upsertCommonFields(it: InsertStatement<Number>, table: IssuesTable, dto: Issue) {
it[table.project] = dto.project
...
fun upsert(dto: Issue) {
IssuesTable.upsert(conflictColumn = IssuesTable.key,
insertBody = {
it[IssuesTable.key] = dto.key
upsertCommonFields(it, this, dto)
updateBaseDTOmetadata(it, this, dto)
},
updateBody = {
upsertCommonFields(it, this, dto)
updateBaseDTOmetadata(it, this, dto)
}
)
}
insert works, but update totally confuses column names and the values to put into them.
Adding support for multiple ON CONFLICT columns would be greatly appreciated.
I have a table with a column named user (which contains an id referring to my own users table). In Postgres, user is a reserved word, which means it's required to put quotes around it when using it in SQL.
I have the following code:
UsageInfos.upsert(
conflictColumn = UsageInfos.user,
insertBody = {
it[user] = id
it[other] = "Value"
},
updateBody = {
it[other] = "Value"
}
)
Which results in the following SQL:
INSERT INTO usageinfos ("other", "user") VALUES ('Value', 86) ON CONFLICT(user) DO UPDATE SET "other"='Value'
Because CONFLICT(user)
is missing quotes, this results in an error.
The correct SQL should be:
INSERT INTO usageinfos ("other", "user") VALUES ('Value', 86) ON CONFLICT("user") DO UPDATE SET "other"='Value'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.