Slackbot
03/04/2020, 10:04 AMEvan R.
03/12/2020, 12:46 PMKabbura
03/12/2020, 7:30 PMlimit
function does not generate sql when the limit size is 0, as the function implementation is
open fun queryLimit(size: Int, offset: Int, alreadyOrdered: Boolean) = buildString {
if (size > 0) {
append("LIMIT $size")
if (offset > 0) {
append(" OFFSET $offset")
}
}
}
Shouldn't be if (size >= 0)
instead?
My use case is that the limit size is generated dynamically, and when it is 0, the sql query results should be empty.Reuben Jacobs
03/14/2020, 11:32 PMcodec
03/16/2020, 6:27 AMcreate(vararg tables: Table){}
method. I just updated to exposed version 0.22. What happened to this method!? 😞Rasheed Sulayman
03/16/2020, 7:39 PMdata
classes directly with exposed, something like:
object Users : Table() {}
// Get list of users
val usersList: List<User> = Users.select { Users.city.eq("a city") }
//Insert users
val allUsers: List<User> = //list of users
val aUser: User = //User instance
Users.insertAll(allUsers) // Inserts everything in to the user table
Users.insert(aUser) // Inserts a single user in to the table.
i.e Something that automatically maps/converts rows to data classes when reading stuff, and vice versa when inserting.Nikky
03/18/2020, 4:20 PMEurope/Berlin
so i tried converting them like so
ISODateTimeFormat.dateTimeParser().parseDateTime(dateString).withZone(DateTimeZone.UTC)
and logging shows me the field should be 2020-03-18T16:17:00.000Z
but when i look into the database i see 2020-03-18 17:17:00
this looks almost as if exposed converts to the local timezone and then discards the timezone info (or DATETIME
has no timezone info?)
how can i make sure i save stuff as UTC
always ?Slackbot
03/19/2020, 10:14 AMDownloadPizza
03/19/2020, 4:42 PMobject Parks : Table("p_parks") {
val id = varchar("p_id", 45)
val longitude = double("longitude")
val latitude = double("latitude")
override val primaryKey = PrimaryKey(id)
}
and im trying to select them by distance to a coordinate c
with latitude lat
and longitude lon
, but i dont want to filter them by smth like "less than 10km away" but i want the 10 nearest. Is there any way to do this without selecting all?DownloadPizza
03/19/2020, 5:08 PMfun distanceBetween(cord1: Coordinates, cord2: Coordinates): Double {
val (lat1deg, lon1deg) = cord1
val (lat2deg, lon2deg) = cord2
val r = 6371e3; // metres
val lat1 = lat1deg.toRadians()
val lat2 = lat2deg.toRadians()
val deltaLat = (lat2deg - lat1deg).toRadians()
val deltaLon = (lon2deg - lon1deg).toRadians()
val a = sin(deltaLat / 2).pow(2) +
cos(lat1) * cos(lat2) * sin(deltaLon / 2).pow(2)
val c = 2 * atan2(sqrt(a), sqrt(1 - a))
return r * c;
}
Sergey Akhapkin
03/23/2020, 12:07 AMobject LocationTable: IntIdTable("LOCATION") {
...
val latitude = double("latitude")
val longitude = double("longitude")
private val doubleT by lazyOf(DoubleColumnType())
fun Expression<Double>.limitToOne() = CustomFunction<Double>("least", doubleT, this, 1.0.lit())
fun Expression<Double>.radians() = CustomFunction<Double>("radians", doubleT, this)
fun Expression<Double>.sin() = CustomFunction<Double>("sin", doubleT, this)
fun Expression<Double>.cos() = CustomFunction<Double>("cos", doubleT, this)
fun Expression<Double>.acos() = CustomFunction<Double>("acos", doubleT, this)
fun Double.lit() = LiteralOp(doubleT, this)
infix fun Expression<Double>.times(v: Expression<Double>) = TimesOp(this, v, doubleT)
infix fun Expression<Double>.times(v: Double) = TimesOp(this, v.lit(), doubleT)
infix fun Expression<Double>.plus(v: Expression<Double>) = PlusOp(this, v, doubleT)
infix fun Column<Double>.minus(v: Double) = BracketOp(MinusOp(this, LiteralOp(doubleT, v), doubleT))
fun distance(coords: Coordinates) =
(latitude.radians().sin() times Math.sin(Math.toRadians(coords.latitude)) plus
latitude.radians().cos() times Math.cos(Math.toRadians(coords.latitude)) times (longitude minus coords.longitude).radians().cos()).limitToOne().acos() times Coordinates.TO_METRIC
}
where
data class Coordinates(val latitude: Double, val longitude: Double) {
companion object {
const val TO_METRIC = 1852.0 * 60.0 * 180.0 / Math.PI
}
}
and this function can be used as following:
query.andWhere { LocationTable.distance(basePoint) lessEq distanceInMeters }
DISCLAIMER:
1. I'm not sure that's 100% right (or idiomatic) way to do that with the exposed (still newcomer for the exposed)
2. I'm pretty sure that's kind of filtering 'closest/nearest' objects is very inefficient (indexes cannot be used), so let consider to use postgis extension or optimizing search in someway e.g. with bounding boxes.Alexander Weickmann
03/23/2020, 1:35 PMwithContext(<http://Dispatchers.IO|Dispatchers.IO>) {
println(TransactionManager.manager.defaultIsolationLevel) // prints 8 = SERIALIZABLE
transaction {
val countBefore = MyDao.find(Op.TRUE).count()
println(countBefore)
println("SLEEP")
Thread.sleep(10000)
println("UPDATE")
val countUpdate = MyDao.find(Op.TRUE).count()
println(countUpdate) // EXPECTING TO BE SAME AS countBefore
}
}
Now I have a separate query that inserts new rows into MyDao, and I trigger it during the 10 seconds of sleep of the first transaction:
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
println(TransactionManager.manager.defaultIsolationLevel) // prints 8 = SERIALIZABLE
transaction {
MyDao.new { ... }
}
}
During setup, I have:
TransactionManager.manager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE
What I expected is that the table behind MyDao gets locked for the time the first transaction is still running. But this is not the case and the first transaction prints 2 different counts as a result ...Markus Jürgens
03/25/2020, 5:54 AMNicolas Lattuada
03/25/2020, 1:28 PMclass PGEnum<T : Enum<T>>(enumTypeName: String, enumValue: T?) : PGobject() {
init {
value = enumValue?.name
type = enumTypeName
}
}
inline fun <reified T : Enum<T>> Table.postgresEnumeration(
columnName: String,
postgresEnumName: String
) = customEnumeration(columnName, postgresEnumName,
{ value -> enumValueOf<T>(value as String) }, { PGEnum(postgresEnumName, it) })
So that column declaration looks like :
internal object MyTable : Table("my_table_name") {
val enumColumnA = postgresEnumeration<MyEnum>("column_name", "postgres_enum_name")
}
rrader
03/27/2020, 7:18 PMExposed
is killer feature and you will not switch to another library if this feature will not be present in that library?Rodrigo Silva
04/01/2020, 11:08 PMGunslingor
04/02/2020, 5:03 PMtransaction {
Categories.insert {
}
}
object Categories : Table() {
val category = varchar("category", 255)
val description = varchar("description", 255)
override val primaryKey = PrimaryKey(category, name = "PK_Category_category")
}
Gunslingor
04/02/2020, 5:58 PMobject Users : IdTable<String>() {
val username = varchar("username",255)
val email = varchar("email",255)
val created = datetime("created").nullable()
val passwordHash = varchar("passwordHash",255).nullable()
val passwordSalt = varchar("passwordSalt",255).nullable()
val avatar = varchar("avatar",255).nullable() //path to users picture
val type = varchar("type",45).nullable() //normal or primium
override val primaryKey = PrimaryKey(username, name = "PK_User_username")
override val id: Column<EntityID<String>>
get() = TODO("Not yet implemented")
}
class User(username: Entity<String>) : EntityClass<String, Users>(){
}
val defaultUsers = listOf<String>()
Not sure why intelliJ is automatically wanting to add the last two lines to the Users object either.... I thought getters and setters were predefined in exposed?Gunslingor
04/04/2020, 3:55 AMpackage com.newsworthy.db.tables
import org.jetbrains.exposed.dao.Entity
import org.jetbrains.exposed.dao.EntityClass
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.dao.id.IdTable
import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.Table
import org.joda.time.DateTime
val defaultCategories = mutableMapOf<EntityID<String>, String>(
EntityID("general", Categories) to "Useless and frowned upon",
EntityID("science", Categories) to "",
EntityID("technology", Categories) to "",
EntityID("world", Categories) to "",
EntityID("local", Categories) to "",
EntityID("top", Categories) to ""
)
class Category(category: EntityID<String>) : Entity<String>(category){
companion object : EntityClass<String, Category>(Categories)
var category by Categories.category
var description by Categories.description
}
object Categories : IdTable<String>("Categories") {
val category = varchar("category", 255).default("general").entityId().default(EntityID("unknown", Categories))
val description = varchar("description", 255).nullable()
override val primaryKey = PrimaryKey(category, name = "PK_Category_category")
override val id: Column<EntityID<String>> = category
}
Gunslingor
04/05/2020, 7:21 AMnrobi
04/10/2020, 9:59 AMSerVB
04/10/2020, 8:34 PMProcessBuilder
, but it seems too rough... Is there an in-memory DB that I can create in JVM and with which Exposed can work?Gunslingor
04/11/2020, 5:29 PMif(notFound) {
val outlet = transaction { Outlet.find { outlet eq outletEntityID }.limit(1).toList()[0] }
val category = transaction { Category.find { Categories.category eq outletData[Outlets.defaultCategory] }.limit(1).toList()[0] }
val title = it.title
val summary = it.description.value.take(255)
val content = it.contents.joinToString()
val discovered = DateTime.now(DateTimeZone.UTC)
val authored = DateTimeFormat.forPattern("EEE MMM dd HH:mm:ss zzz yyyy").parseDateTime("${it.publishedDate}")
val thumbnailUrl = getReportFeatureImage(it) ?: outletData[defaultReportThumbnailUrl]
transaction {
Report.new {
this.url = url
this.outlet =outlet
this.category = category
this.title = title
this.summary = summary
this.content = content
this.discovered = discovered
this.authored = authored
this.thumbnailUrl = thumbnailUrl
}
}
counts.added += 1
} else {
counts.existing += 1
}
spand
04/13/2020, 1:26 PM1.4.199
. Would it be possible for Exposed to depend on that version somehow instead of having to manually keeping it in sync ?spand
04/14/2020, 6:57 PMLuis Munoz
04/15/2020, 6:38 PMMohamed Ali
04/15/2020, 10:03 PMAlex
04/16/2020, 10:03 AMSrSouza
04/21/2020, 8:13 PMchristophsturm
04/27/2020, 8:25 AMchristophsturm
04/27/2020, 8:25 AMtapac
04/27/2020, 10:17 AMchristophsturm
04/27/2020, 10:23 AMtapac
04/27/2020, 10:29 AMexposed.test.dialects=sqlite,h2,h2_mysql,postgresql,postgresqlng
as system properties.christophsturm
04/27/2020, 11:06 AM./gradlew -Dexposed.test.dialects=sqlite,h2,h2_mysql,postgresql,postgresqlng build
does not work for me. it still wants to start mysqltapac
04/27/2020, 12:38 PMchristophsturm
04/27/2020, 2:36 PMorg.jetbrains.exposed.DefaultsTest
in the java-time module