Kristian Notari
Kristian Notari
Explore posts from servers
DHDistant Horizons
Created by Kristian Notari on 6/8/2024 in #help-me
Moving fast remove lods behind, regenerate after a while
No description
16 replies
KKysely
Created by Kristian Notari on 3/6/2024 in #help
Static/reusable custom window functions
Hello, I'm trying to buld a properly typed array_agg window function and would like to reuse the existing FunctionModule in a reusable way, so to have orderby, over, and so on. Is there a way to get the function module you get from fn.agg outside of an expression builder and without creating a puppet kysely instance, so to create an array_agg function and return what fn.agg return but properly typed? As an example:
const array_agg = (expr: T) => sql.fn.agg<DeriveFrom<T>>('array_agg', [expr])
const array_agg = (expr: T) => sql.fn.agg<DeriveFrom<T>>('array_agg', [expr])
(right now there's no sql.fn forcing you to use a kysely instance or an expression builder to access the fn function module)
3 replies
KKysely
Created by Kristian Notari on 2/28/2024 in #help
On Conflict do update set ALL to be inserted columns
Here I am once again with a question for the on conflict bit in postgres. Would there be a way to automatically compose an update set statement for the on conflict do update bit with the information about all the columns we're going to insert, and automatically do an update with the excluded for those? Example here
5 replies
KKysely
Created by Kristian Notari on 1/10/2024 in #help
cmpr as eb call SqlBool return type
Hello, missed a couple of updates and now I'm back updating to latest. Found out eb.cmpr has been removed and I now need to use eb() as a function. Is there an easy way to get back a boolean instead of a SqlBool ? Before I just needed to call it like eb.cmpr<boolean>. Thanks! (I mean, other than a plain type assertion)
4 replies
KKysely
Created by Kristian Notari on 9/21/2023 in #help
Error "isSelectQueryBuilder" while using doUpdateSet on conflict
Hello, I get an error when dealing with an update object factory for doUpdateSet expression during an on conflict statement for an insert. From my experiments, if the select type of the column is different (not assignable to) the insert/update types than something breaks at the type level and gives me an error Repro: https://kyse.link/?p=s&i=Wt7lre2AUUH7EdAInOja
16 replies
KKysely
Created by Kristian Notari on 3/17/2023 in #help
RawBuilder is not "Compilable"
How one should execute RawBuilders coming from (for example)
```
since they're not "Compilable" things? I know you can pass from
```
since they're not "Compilable" things? I know you can pass from
sqlcustomsql.execute({ getExecutor: () => executor }) ``` since I have a custom executor, but why is that? Is there another way?
30 replies
KKysely
Created by Kristian Notari on 3/15/2023 in #help
Subquery type error when using generics
I have the following simple query being generated by my function f:
const f = () => queryBuilder
.deleteFrom(`table as t1`)
.whereExists(qb => qb.selectFrom(`table as t2`)
.whereRef('t1.col1', '>=', 't2.col1')
)
const f = () => queryBuilder
.deleteFrom(`table as t1`)
.whereExists(qb => qb.selectFrom(`table as t2`)
.whereRef('t1.col1', '>=', 't2.col1')
)
and it works fine. If I add a generic for reusing the same function with different tables (all sharing the common col1 column) it works fine, until I get to the sub query whereRef (even if I constraint the generic to a single value, which is the same table as before):
const f = <T extends 'table'>(table: T) => queryBuilder
.deleteFrom(`${table} as t1`)
.whereExists(qb => qb.selectFrom(`${table} as t2`)
/* here it can't find the refs to t1.col1 or t2.col1 */.whereRef('t1.col1', '>=', 't2.col1')
)
const f = <T extends 'table'>(table: T) => queryBuilder
.deleteFrom(`${table} as t1`)
.whereExists(qb => qb.selectFrom(`${table} as t2`)
/* here it can't find the refs to t1.col1 or t2.col1 */.whereRef('t1.col1', '>=', 't2.col1')
)
12 replies
KKysely
Created by Kristian Notari on 3/7/2023 in #help
createQueryId
Is this function supposed to be exported and used in users code? I'm handling query execution with a custom executor and the executeQuery method asks me for a QueryId. Am I supposed to use kysely internal implementation or am I free to use a custom one? It's just a random string I see, but does it involve something else internally? I'm asking cause the default import is set to: import { createQueryId } from "kysely/dist/cjs/util/query-id"
20 replies
KKysely
Created by Kristian Notari on 2/21/2023 in #help
Insert expression type safe
Is there a way to make .expression calls while inserting to a table to return an "InsertObject" or an array of column name / value as when using .values method so to have type safety in the query? Example right now:
type Table = { a: string, b: number }
const query = database.insertInto("table").columns(['a']).expression(qb => qb.selectFrom('other_table').select('a'))
// this works but will crash at runtime, cause you need both a nd b columns
type Table = { a: string, b: number }
const query = database.insertInto("table").columns(['a']).expression(qb => qb.selectFrom('other_table').select('a'))
// this works but will crash at runtime, cause you need both a nd b columns
Example wanted:
type Table = { a: string, b: number }
const query1 = database.insertInto("table").columns(['a'] /* type error*/).expression(qb => qb.selectFrom('other_table').select('a'))

const query2 = database.insertInto("table").expression(qb => qb.selectFrom('other_table').select(['a', 'b as bChanged']).mapping({
a: "a",
b: "bChanged"
}))
// this or something to link values to columns so that order is not important but it's then decided by the query builder collecting key/values pairs into an array of columns and then array of select in the expression as in:
// insert into table(a, b) select a, b from other_table
type Table = { a: string, b: number }
const query1 = database.insertInto("table").columns(['a'] /* type error*/).expression(qb => qb.selectFrom('other_table').select('a'))

const query2 = database.insertInto("table").expression(qb => qb.selectFrom('other_table').select(['a', 'b as bChanged']).mapping({
a: "a",
b: "bChanged"
}))
// this or something to link values to columns so that order is not important but it's then decided by the query builder collecting key/values pairs into an array of columns and then array of select in the expression as in:
// insert into table(a, b) select a, b from other_table
24 replies
KKysely
Created by Kristian Notari on 2/20/2023 in #help
Property "values" missing when Inspecting InsertQuery ValuesNode
I'm having some troubles upgrading from 0.22.0 to 0.23.4, because I have a custom plugin which gets some columns as input for each database table and prevent any other column to be used as the target of an InsertQuery (this way I can silently pass { id: 42, username: "John", nonExistingColumn: "error at runtime" } as an insert value for my user table without worrying about excessive properties in the values. I have overriden the:
protected override transformInsertQuery(_node: InsertQueryNode): InsertQueryNode
protected override transformInsertQuery(_node: InsertQueryNode): InsertQueryNode
and before the upgrade I was checking if my insert query values are actual values I need to filter to remove values for non existing columns but right now I have this error saying there's no values property inside the values node:
const newValues = node.values?.kind === `ValuesNode` ? transformValues(node.values) : ...
const newValues = node.values?.kind === `ValuesNode` ? transformValues(node.values) : ...
This is due to the node.values being a OperationNode which only has:
export interface OperationNode {
readonly kind: OperationNodeKind;
}
export interface OperationNode {
readonly kind: OperationNodeKind;
}
There used to be a ValuesNode instead, after checking for its kind "ValuesNode". But now it's just an OperationNode and I can't access values directly.
export interface ValuesNode extends OperationNode {
readonly kind: 'ValuesNode';
readonly values: ReadonlyArray<ValuesItemNode>;
}
export interface ValuesNode extends OperationNode {
readonly kind: 'ValuesNode';
readonly values: ReadonlyArray<ValuesItemNode>;
}
Do you know how to solve?
7 replies