Sandeep Chandra
04/06/2021, 9:28 AMEndre Deak
04/12/2021, 8:12 PM0.30.1
- Query.prepareSql(queryBuilder: QueryBuilder)
is now internal. What’s the right way to print out the Query SQL then?Luca Piccinelli
04/16/2021, 12:11 PMLuca Piccinelli
04/16/2021, 3:14 PMCLOVIS
04/17/2021, 8:27 AMobject Profiles : IntIdTable() {
val email = varchar("email", 50).uniqueIndex() // important!
val name = varchar("name", 50)
}
Looking at the logs, it seems that the table is created correctly by Exposed:
DEBUG Exposed - CREATE TABLE IF NOT EXISTS Profiles (id INT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(50) NOT NULL, name VARCHAR(50) NOT NULL)
DEBUG Exposed - ALTER TABLE Profiles ADD CONSTRAINT Profiles_email_unique UNIQUE (email)
Because of the unique index, I would expect insert
requests with an email already present in the database, to fail:
Profiles.insert { profile ->
profile[this.email] = email
profile[this.name] = name
}
In the above example, I would expect an insert
to be fail if the email is already used by another profile.
Nothing seems weird in debug either;
DEBUG Exposed - INSERT INTO Profiles (email, name) VALUES ('some random <http://email.fr|email.fr>', 'my full name')
However, when running this code multiple times, instead of failing on the insert
, it simply replaces the previous entry that had the same email.
In case it's relevant, I'm using MariaDB.
For obvious reasons, I don't want users of the software to be able to replace other accounts. I'm not sure if the current behavior is 'normal' or 'bugged', so I'm asking here whether:
1. Is it normal behavior, or should I submit a bug report?
2. If this is normal behavior, what should I change in my code so the insert
fails (with an exception or something else)?Miroslav Sobotka
04/19/2021, 7:34 AMselect count(ID) from employer
The ID column is primary key, so uniq and has no nulls.
Employer.slice(Employer.Id).count()
produces select count(*) from employer
Thanks!dave08
04/19/2021, 5:17 PMJohn Pena
04/19/2021, 8:36 PMTransaction attempt #0 failed: org.postgresql.util.PSQLException: ERROR: operator does not exist: "MyEnumColumn" = character varying\n Hint: No operator matches the given name and argument types. You might need to add explicit type casts
Dominick
04/23/2021, 3:33 PMUserTable.update({ UserTable.userId eq userId }) {
it[UserTable.hashedPassword] = hash(randomAlphanumerical(8))
}
Luca Piccinelli
04/24/2021, 2:00 PMobject BuddyTable: IdTable<Int>("toh.buddy"){
override val id = integer("id").autoIncrement("toh.buddy_seq_id").entityId()
val name = varchar("name", 50)
val hero = reference("hero_id", HeroTable)
}
class BuddyDao(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<BuddyDao>(BuddyTable)
var name by BuddyTable.name
var hero by HeroDao referencedOn BuddyTable.hero
}
override fun save(entity: Buddy): Int = transaction {
BuddyTable.insert {
it[name] = entity.name
it[hero] = entity.hero.id
}[BuddyTable.id].value
}
In postgres it looks like it is not using the sequence to generate the new id (also if i don't override the id field)
Prefixing or not with the schema "toh" doesn't change.
The error is
Detail: Key (id)=(3) already exists.. Statement(s): INSERT INTO toh.buddy (hero_id, "name") VALUES (?, ?)
org.jetbrains.exposed.exceptions.ExposedSQLException: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "buddy_pkey"
Detail: Key (id)=(3) already exists.
It does 3 transaction attempts with ids 1, 2 and 3tapac
04/25/2021, 7:44 PMAli Olfat
04/26/2021, 4:39 AMinsertIgnore
on a non IdTable? I'm currently querying for it right afterwards but was wondering if there is a cleaner wayLuca Sas
04/27/2021, 6:48 PMoverride fun tableExists(table: Table): Boolean {
val tableScheme = table.tableName.substringBefore('.', "").takeIf { it.isNotEmpty() }
val scheme = tableScheme?.inProperCase() ?: TransactionManager.current().connection.metadata { currentScheme }
val allTables = getAllTableNamesCache().getValue(scheme)
return allTables.any {
when {
tableScheme != null -> it == table.nameInDatabaseCase()
scheme.isEmpty() -> it == table.nameInDatabaseCase()
else -> it == "$scheme.${table.tableNameWithoutScheme}".inProperCase()
}
}
}
What happens here by looking at the debugger is that alltables
is [ "public.tablename", "public.someothertablename" ]
but table.name
misses the schema name and I am not sure why. The code is fairly straightforward and I used SchemaUtils.create
successfully in the past.Dominick
04/28/2021, 3:24 AMDominick
04/28/2021, 4:02 AMval dataSource = HikariDataSource().apply {
maximumPoolSize = 20
driverClassName = "com.mysql.jdbc.Driver"
jdbcUrl = File("jdbc_url.txt").readText()
isAutoCommit = false
}
Database.Companion.connect(dataSource)
transaction {
SchemaUtils.create(MediaPropertiesTable)
SchemaUtils.create(MediaContentTable)
SchemaUtils.create(UserAPIKeysTable)
SchemaUtils.create(UserTable)
}
The file jdbc_url.txt does exist and has a connection url generated from pterodactyl
UPDATE: Tried removing pterodactyl from the equation and still doesnt work. It gets past the create code and all, nothing gets logged even after adding addLogger(StdOutSqlLogger)
and the tables arent in the db.Joost Klitsie
04/29/2021, 7:35 AMchristophsturm
04/30/2021, 1:42 PMtransaction(db) {..}
it will avoid threadlocals, but it seems that all exposed calls inside the transaction still get their transaction from a threadlocal. so it only works if the thread stays the same, and for example it wont work if i have callbacks (or coroutines) that potentielly run in different threads.Emil Kantis
05/02/2021, 5:33 PM<http://dao.Companies.org|dao.Companies.org>_id is not in record set
.
All tables are created in the same transaction as the test then everything is rolled back.
I've tried using both H2 and SQLite, getting same error with both.. Not sure where to start looking. Most search hits seems to be related to renaming the id column, but this is a FK to another entityAli Albaali
05/13/2021, 5:43 PMFlow
from a query?spand
05/18/2021, 8:03 AMINSERT INTO Tbl (parentId, number)
VALUES (42,
COALESCE((SELECT MAX(aTbl.number) FROM Tbl as aTbl WHERE aTbl.parentId = 42) + 1, 1)
);
I kind of expected a way to turn a query into an Expression<Int>.Jamy
05/25/2021, 6:16 AMRenaud
05/28/2021, 2:30 PMfor loop
Publication.new { ... }
2. Insert via entity table
Publication.table.batchInsert
1? 2? I’m not sureESchouten
06/07/2021, 4:04 PMobject Person : UUIDTable() {
val name = varchar("name", 255)
val address = reference("address", Address)
}
object Company : UUIDTable() {
val name = varchar("name", 255)
val address = reference("address", Address)
}
object Address : UUIDTable() {
val number = varchar("number", 255)
val street = varchar("street", 255)
val city = varchar("city", 255)
val zipcode = varchar("zipcode", 255)
val country = varchar("country", 255)
}
Emil Kantis
06/07/2021, 8:36 PM// Entity
class Client(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<Client>(Clients)
// Some code omitted
var tags2: List<String> by jsonStore(Clients.tags)
}
// Delegate provider
inline fun <reified S, T : Comparable<T>> Entity<T>.jsonStore(column: Column<String>) = JsonStore<T, S>(
serializer(),
column,
{ column.lookup() },
{ thisRef, property, value -> column.setValue(thisRef, property, value) }
)
// Delegate
class JsonStore<T : Comparable<T>, S>(
val serializer: KSerializer<S>,
val column: Column<String>,
val lookup: (Column<String>) -> String,
val write: (Entity<T>, KProperty<*>, String) -> Unit
) {
operator fun getValue(thisRef: Any?, property: KProperty<*>): S =
json.decodeFromString(serializer, lookup(column))
operator fun setValue(thisRef: Entity<T>, property: KProperty<*>, value: S) =
write(thisRef, property, json.encodeToString(serializer, value))
}
Jeff
06/10/2021, 9:17 AM6371 * ACOS(COS(RADIANS(:latitude)) * COS(RADIANS(`lat`)) * COS(RADIANS(:longitude) - RADIANS(`lng`)) + SIN(RADIANS(:latitude)) * SIN(RADIANS(`lat`))) AS `distance`
Anyone with an idea on how to implement this?Matias Rozenblum
06/14/2021, 2:34 PMtapac
06/14/2021, 6:10 PMexposed-gralde-plugin
is here with a very small but usefult gradle task which allows to generate tables definitions by existing scheme.
https://plugins.gradle.org/plugin/com.jetbrains.exposed.gradle.plugin
The main idea is allow easily migrate your large (or not so large) existing projects to Exposed.
Please check a documentation on github and share your ideas on things that can be improved/added to a gradle plugin. For now I think that it can be useful to generate/validate schemas or prepare migration scripts (like ShemaUtils do). What do you think?
The on of the next steps is to have intellij-idea plugin to have same things in the IDE, so share your thoughts about that too:)
P.S. There can be bugs for sure:)Tim McCormack
06/20/2021, 10:54 PMDatabase
instance in separate transactions in two separate threads... I would expect to see uncommitted reads and similar. But I can't seem to reproduce that with a test. Does Exposed do something to ensure isolation?dave08
06/28/2021, 3:11 PMgenerateExposedTask
has been stuck for more than half-an-hour without crashing nor telling me what's wrong... how can I debug this?rcd27
07/02/2021, 7:16 AMexposed
. The task is: store ~2.5K items in one table with ability to full-text-search against the item name
field. Which database supported by Exposed
is my choice of best performance?rcd27
07/02/2021, 7:16 AMexposed
. The task is: store ~2.5K items in one table with ability to full-text-search against the item name
field. Which database supported by Exposed
is my choice of best performance?crummy
07/02/2021, 8:04 AM