Adam Crane
02/23/2021, 7:40 PMJoel
02/24/2021, 2:26 PMAdam Crane
02/24/2021, 2:30 PMselect a.* from account a
join Routine('user_id') as rt on a.id = rt.id;
Basically the routine returns a list of account ids the user is allowed to access. Unfortunately, I have to use the routine and don't have access to the inner workings.Joel
02/24/2021, 3:24 PMJoel
02/24/2021, 3:25 PMJoel
02/24/2021, 3:25 PMEndre Deak
02/25/2021, 5:12 PMdescribe
then you can join it. So something like
object RoutineUserTable : Table() {
override fun describe(s: Transaction, queryBuilder: QueryBuilder) {
queryBuilder.append("Routine('user_id')")
}
}
and this can be joined. I’ve seen this in one of the open github issuesAdam Crane
02/25/2021, 5:18 PM'user_id'
could be different each time I use the table.Endre Deak
02/25/2021, 5:26 PMuser_id
out as a parameter at a higher level, then create the table dinamically:
fun createTable(param: String): Table() = object: Table() {
override fun describe(...) {
queryBuilder.append("Stuff(${param})")
}
}
Adam Crane
02/25/2021, 6:03 PMclass FunctionBasedTable(private val inputValue: String) : Table("schema.Function('$inputValue')") {
val outputValue = varchar("output_column", 10)
}
Adam Crane
02/25/2021, 10:25 PMclass GetUserAccounts(private val userId: String, private val alias: String) : Table(alias) {
val accountId = varchar("Account_Id", 18)
override fun describe(s: Transaction, queryBuilder: QueryBuilder) {
queryBuilder.append("schema.Get_User_Accounts('$userId') AS $alias")
}
}
fun getIds(userId: String) : List<String> {
return transaction {
val table = GetUserAccounts(userId, "gua")
table
.selectAll()
.withDistinct()
.mapNotNull { row ->
row[table.accountId]
}
}
}
This also works when it is used as a join table!Joel
02/26/2021, 9:43 PM