Swap
Swap
KKysely
Created by Swap on 8/1/2023 in #help
Plugin for auto-update "updated_at" field
Thanks 🙂
11 replies
KKysely
Created by Swap on 8/1/2023 in #help
Plugin for auto-update "updated_at" field
I can go with the DB triggers but they also cause performance issues.
11 replies
KKysely
Created by Swap on 8/1/2023 in #help
Plugin for auto-update "updated_at" field
Absolutely, I agree 😄 What will your recommendation be for separating this functionality be?
11 replies
KKysely
Created by Swap on 8/1/2023 in #help
Plugin for auto-update "updated_at" field
Going further, i have removed SetUpdatedAtTransformer class and my modified plugin is follows:
export class UpdatedAtPlugin implements KyselyPlugin {

transformQuery(args: PluginTransformQueryArgs): RootOperationNode {
if (args.node.kind === "UpdateQueryNode") {
const arr: ColumnUpdateNode[] = [];

arr.push(...args.node.updates);
arr.push(
{
kind: 'ColumnUpdateNode',
column: {
kind: 'ColumnNode',
column: { kind: 'IdentifierNode', name: 'updated_at' }
},
value: { kind: 'ValueNode', value: '${new Date()}' }
}
);

return {
...args.node,
updates: arr,
};
}

return args.node;
}

transformResult(
args: PluginTransformResultArgs
): Promise<QueryResult<UnknownRow>> {
return Promise.resolve(args.result);
}
}
export class UpdatedAtPlugin implements KyselyPlugin {

transformQuery(args: PluginTransformQueryArgs): RootOperationNode {
if (args.node.kind === "UpdateQueryNode") {
const arr: ColumnUpdateNode[] = [];

arr.push(...args.node.updates);
arr.push(
{
kind: 'ColumnUpdateNode',
column: {
kind: 'ColumnNode',
column: { kind: 'IdentifierNode', name: 'updated_at' }
},
value: { kind: 'ValueNode', value: '${new Date()}' }
}
);

return {
...args.node,
updates: arr,
};
}

return args.node;
}

transformResult(
args: PluginTransformResultArgs
): Promise<QueryResult<UnknownRow>> {
return Promise.resolve(args.result);
}
}
But, getting type error
TS2322: Type  { kind: "ValueNode"; value: string; }  is not assignable to type  OperationNode 
Object literal may only specify known properties, and  value  does not exist in type  OperationNode 
column-update-node.d.ts(6, 14): The expected type comes from property  value  which is declared here on type  ColumnUpdateNode
TS2322: Type  { kind: "ValueNode"; value: string; }  is not assignable to type  OperationNode 
Object literal may only specify known properties, and  value  does not exist in type  OperationNode 
column-update-node.d.ts(6, 14): The expected type comes from property  value  which is declared here on type  ColumnUpdateNode
11 replies
KKysely
Created by Swap on 7/11/2023 in #help
Postgres Full Text Search
Seems everyone is happy now :), thanks for your help and time @koskimas
19 replies
KKysely
Created by Swap on 7/11/2023 in #help
Postgres Full Text Search
I dont have installed any, but seems Intellij Idea has builtin to check sql
19 replies
KKysely
Created by Swap on 7/11/2023 in #help
Postgres Full Text Search
19 replies
KKysely
Created by Swap on 7/11/2023 in #help
Postgres Full Text Search
its showing <query expression> expected, got ''english''
19 replies
KKysely
Created by Swap on 7/11/2023 in #help
Postgres Full Text Search
Error is resolved after upgrading to the latest one, thanks
19 replies
KKysely
Created by Swap on 7/11/2023 in #help
Postgres Full Text Search
Hey @koskimas , thanks for the reply, now its far better than my current implementation 😄 my lint is still complaining for the 'english' but seems managable for now, but for now i am getting error for the eb expression TypeError: eb is not a function
19 replies
KKysely
Created by Swap on 6/5/2023 in #help
Unable to insert geometry Postgres
Thanks @koskimas , it is more typesafe now. I really appreciate your time and efforts to build this wonderful library. 🙂
8 replies
KKysely
Created by Swap on 6/5/2023 in #help
Unable to insert geometry Postgres
Hey @koskimas , thanks for the reply. Both solutions are working as expected and i am able to insert point :). i am using following code to retrieve stored coordinates from the database
await this.db.selectFrom("location")
.where(sql`ST_DWithin( coordinates::geography,ST_MakePoint(${lat},${long}),8000)`)
.select(
[
sql<string>`ST_X(coordinates)`.as("latitude"),
sql<string>`ST_Y(coordinates)`.as("longitude"),
"name"
]
)
.execute()
await this.db.selectFrom("location")
.where(sql`ST_DWithin( coordinates::geography,ST_MakePoint(${lat},${long}),8000)`)
.select(
[
sql<string>`ST_X(coordinates)`.as("latitude"),
sql<string>`ST_Y(coordinates)`.as("longitude"),
"name"
]
)
.execute()
Above code is working as exepected but, i was wondering is there any other better approach for the above query?
8 replies