bombillazo
bombillazo
Explore posts from servers
KKysely
Created by bombillazo on 1/19/2025 in #help
Convert record from Function call (RPC) to JSON
Hello, I am using raw SQL to run a function that returns a record, but it is returning it to the TS domain as a string like this:
"(b38ed355-c2b0-4998-aff9-8c8dc429ffe5,My_Test_Key,valid,aead-det,22,\"\\\\x7067736f6469756d\",\"2025-01-19 02:09:04.392092+00\",,\"\")"
"(b38ed355-c2b0-4998-aff9-8c8dc429ffe5,My_Test_Key,valid,aead-det,22,\"\\\\x7067736f6469756d\",\"2025-01-19 02:09:04.392092+00\",,\"\")"
instead of a JSON object with those values in key/value pairs. How can Kysely parse this value and convert it to an object?
4 replies
KKysely
Created by bombillazo on 1/18/2025 in #help
Generating dynamic raw query help
Hello, we are trying to create a function utility to call RPCs, we want to dynamically generate the following SQL query:
SELECT my_function(arg1 => 'some_value', arg2 => 123);
SELECT my_function(arg1 => 'some_value', arg2 => 123);
We are trying the following
input = Object.entries(payload).map(([key, value]) => {
return sql`${sql.raw(key)} => ${sql.val(value)}`;
});

const x = sql`SELECT ${sql.raw(name)}(${sql.raw(input.join(','))})`;
input = Object.entries(payload).map(([key, value]) => {
return sql`${sql.raw(key)} => ${sql.val(value)}`;
});

const x = sql`SELECT ${sql.raw(name)}(${sql.raw(input.join(','))})`;
But the outputs have been things like: SELECT my_function($1, $2) SELECT my_function([object Object],[object Object]) Is there a Kysely helper function to generate the arg1 => 'some_value', arg2 => 123 section of my query, or how should I go about it? Thanks for any help!
4 replies
KKysely
Created by bombillazo on 1/15/2025 in #help
How can I join 2 tables where 1 side is a JSON property in a JSON column?
I am trying this:
db.selectFrom('my_table')
.selectAll(['my_table'])
.innerJoin(
'table_2',
'table_2.id',
sql`my_table.metadata->>'id'`,
)
.select(['table_2.name'])
db.selectFrom('my_table')
.selectAll(['my_table'])
.innerJoin(
'table_2',
'table_2.id',
sql`my_table.metadata->>'id'`,
)
.select(['table_2.name'])
I am getting a type issue:
Argument of type 'RawBuilder<unknown>' is not assignable to parameter of type 'AnyJoinColumn<KyselyDB, "my_table", "table_2"> | AnyJoinColumnWithTable<KyselyDB, "my_table", "table_2">
Argument of type 'RawBuilder<unknown>' is not assignable to parameter of type 'AnyJoinColumn<KyselyDB, "my_table", "table_2"> | AnyJoinColumnWithTable<KyselyDB, "my_table", "table_2">
6 replies
KKysely
Created by bombillazo on 12/24/2024 in #help
Executing stored procedure in MS SQL
Hello, I've used Kysely for PG DB and love it, now I have a MSS SQL project and need to execute some Stored Procedures, how would one do this?
4 replies
DDeno
Created by bombillazo on 12/13/2024 in #help
Issues migrating dependencies from v1.x to v2.x
Hey, I'm facing some issues when upgrading from v1.146 to v2. We have a backend monorepo that uses import_map.json files to manage dependencies per sub module in our monorepo. We don't have a package.json for Deno (only for our Next.js frontend which is still on node). We do have a deno.jsonc at the root level of our project. After upgrading to Deno v2, we get these errors when we run or try to install:
# install
error: Error in @stripe/[email protected] parsing version requirement for dependency "react-dom": ">=16.8.0 && <=^19.0.0"
deno install
Caused by:
0: Invalid version requirement
1: Unexpected character.
>=16.8.0 && <=^19.0.0
~
# install
error: Error in @stripe/[email protected] parsing version requirement for dependency "react-dom": ">=16.8.0 && <=^19.0.0"
deno install
Caused by:
0: Invalid version requirement
1: Unexpected character.
>=16.8.0 && <=^19.0.0
~
# run
Running service
Watcher Process started.
error: Could not find a matching package for 'npm:[email protected]' in the node_modules directory. Ensure you have all your JSR and npm dependencies listed in your deno.json or package.json, then run `deno install`. Alternatively, turn on auto-install by specifying `"nodeModulesDir": "auto"` in your deno.json file.

Watcher Process started.
error: [ERR_MODULE_NOT_FOUND] Cannot find module 'file:///Users/app/node_modules/type-fest/index.js' imported from 'file:///Users/app/@types/date.types.ts'
at file:///Users/app/@types/date.types.ts:8:24
# run
Running service
Watcher Process started.
error: Could not find a matching package for 'npm:[email protected]' in the node_modules directory. Ensure you have all your JSR and npm dependencies listed in your deno.json or package.json, then run `deno install`. Alternatively, turn on auto-install by specifying `"nodeModulesDir": "auto"` in your deno.json file.

Watcher Process started.
error: [ERR_MODULE_NOT_FOUND] Cannot find module 'file:///Users/app/node_modules/type-fest/index.js' imported from 'file:///Users/app/@types/date.types.ts'
at file:///Users/app/@types/date.types.ts:8:24
this is part of our import_map.json file:
{
"imports": {
"kysely": "https://esm.sh/[email protected]",
"pg": "npm:[email protected]",
"query-string": "https://esm.sh/[email protected]?dts",
"remeda": "https://esm.sh/[email protected]?dts",
"stripe": "https://esm.sh/[email protected]?dts",
"type-fest": "npm:[email protected]",
"zod": "https://deno.land/x/[email protected]/mod.ts"
}
}
{
"imports": {
"kysely": "https://esm.sh/[email protected]",
"pg": "npm:[email protected]",
"query-string": "https://esm.sh/[email protected]?dts",
"remeda": "https://esm.sh/[email protected]?dts",
"stripe": "https://esm.sh/[email protected]?dts",
"type-fest": "npm:[email protected]",
"zod": "https://deno.land/x/[email protected]/mod.ts"
}
}
What is the proper way to step Deno dependencies for v2 in a monorepo, and should we keep using import maps?
2 replies
DDeno
Created by bombillazo on 12/13/2024 in #help
Deno vs Node `Intl.DateTimeFormat().resolvedOptions()` discrepancies
No description
10 replies
KKysely
Created by bombillazo on 9/26/2024 in #help
Kysely client usage and pooling question
Hello, We have a long running server that at the moment creates a single Kysely instance. It is setup to use pg pooling. We have a util function called getKysely which returns this instance and is used throught our backend , like on every request handler that calls the DB. So in theory multiple concurrent requests call this function to get the Kysely client and make queries. We are noticing that even within the same API endpoint handler, executing queries with a fetched client seems to be running on different connections. We think this because we sometimes execute raw sql queries which change the role of the connection, but later on using the same client we execute a query to check the current role and it is not the one set up previously. I am curious about how Kysely internally uses pooling, does it fetch a connection from the pool on every query? I know we are using a singleton, but how can I make sure that Kysely uses a single connection throughout the scope of a single request?
7 replies
HHono
Created by bombillazo on 8/22/2024 in #help
Cannot load `hono` from JSR
Hello, we're using Deno and are getting the following error when importing hono using the jsr:@hono/hono import which has worked for us for the past months:
import 'https://registry-staging.deno.com/@hono/hono/meta.json' failed: error sending request for url (https://registry-staging.deno.com/@hono/hono/meta.json): error trying to connect: dns error: failed to lookup address information: nodename nor servname provided
import 'https://registry-staging.deno.com/@hono/hono/meta.json' failed: error sending request for url (https://registry-staging.deno.com/@hono/hono/meta.json): error trying to connect: dns error: failed to lookup address information: nodename nor servname provided
Any way to fix this issue?
2 replies
DDeno
Created by bombillazo on 8/13/2024 in #help
Reset position of terminal cursor when calling io.writeAllSync()
Currently using io.writeAllSync, the next data is written where the last data left off, even with a new line the cursor is kept horizontally in the position that was left. I tried the ansi library cursorBack function but it did not work, how can I control or reset the cursor?
2 replies
DDeno
Created by bombillazo on 8/13/2024 in #help
How to log Deno.Command output in real time (not after command completes)
Hello, is there a guide on how to log stdout with a Deno.Command is running, not just after it completes?
6 replies
HHono
Created by bombillazo on 8/11/2024 in #help
Return early from middleware
Hello, I want to return a 200 response from a middleware if certain conditions are not met, else run await and cleanup after the await. How can I return early from the middleare function?
3 replies
HHono
Created by bombillazo on 8/8/2024 in #help
Match both `/` and `/:id` routes the the same router
Hello, is there any way to handle 2 routes in the same router? We want to handle requests coming to both / and /:id to handle when id is undefined or has a value.
6 replies
DDeno
Created by bombillazo on 7/3/2024 in #help
Is there any way to force a Deno dependency to use a specific version of std?
We're having an issue were a dependency we are importing from npm with the npm: identifier is trying to use a node lib that only exisits up to std v0.177.0, specifically the tty lib. Our main std version is in 0.244.0 specified in our import_map.json file. Is there any way to specify this 3rd party dep to use the std version it requires to work?
2 replies
KKysely
Created by bombillazo on 6/20/2024 in #help
How to do `LIKE ANY` query in Kysely?
Hello, I am trying to build this query in Kysely but have no idea how to properly insert the ANY into the query.
SELECT *
FROM your_table
WHERE your_column LIKE ANY (ARRAY[
'%suffix1',
'%suffix2',
'%suffix3'
]);
SELECT *
FROM your_table
WHERE your_column LIKE ANY (ARRAY[
'%suffix1',
'%suffix2',
'%suffix3'
]);
Any constructs with kysely that I should use in particular?
3 replies
KKysely
Created by bombillazo on 5/17/2024 in #help
Dynamic conditional raw query question
Hello there, Im trying to create a dynamic query like this:
await sql`SELECT
column AS "data"
FROM my_table
${type ? ` WHERE type = ${type}` : ''};`.execute(client);
await sql`SELECT
column AS "data"
FROM my_table
${type ? ` WHERE type = ${type}` : ''};`.execute(client);
But kysely is trying to do substitution where I have my TS logic to either add the WHERE clause or not. How can I fix this ?
6 replies
DDeno
Created by bombillazo on 4/11/2024 in #help
How to upgrade `import_map.json` package versions?
Hello, in node I used ncu to check for new package versions and automatically update the versions. Is there any utility for deno to scna my packages and check if there are new versions?
4 replies
KKysely
Created by bombillazo on 4/11/2024 in #help
jsonArrayFrom with `as` not being typed
I have the following query
await db
.selectFrom('user')
.selectAll()
.select((eb) => [
jsonArrayFrom(
eb
.selectFrom('book')
.selectAll()
.where('book.is_enabled', '=', true)
).as('books'),
])
.execute();
await db
.selectFrom('user')
.selectAll()
.select((eb) => [
jsonArrayFrom(
eb
.selectFrom('book')
.selectAll()
.where('book.is_enabled', '=', true)
).as('books'),
])
.execute();
but the resulting query is not seeing the jsonArrayFrom field with the name books , rather it types it like this:
{
[x: string]: {
created_at: TimestampTZ;
description: string | null;
id: string;
label: string | null;
name: string;
is_enabled: boolean;
}[];
... 5 more ...;
name: string;
}[]
{
[x: string]: {
created_at: TimestampTZ;
description: string | null;
id: string;
label: string | null;
name: string;
is_enabled: boolean;
}[];
... 5 more ...;
name: string;
}[]
How can i fix this?
25 replies
KKysely
Created by bombillazo on 4/2/2024 in #help
Kysely setup in monolith API
Hello, we have a basic http server with a basic router and a PostgreSQL database. We're wondering what is the proper setup to use the Kysely client in our routes to make calls to the database. Should there be a singleton client that is used across routes, or do we need to instantiate a kysely client on every request ?
10 replies
KKysely
Created by bombillazo on 2/9/2024 in #help
How do I use `WHERE NOT EXISTS`?
I am trying to write the followng where condition:
INSERT INTO Filing (location_id, filing_date, other_columns)
SELECT L.location_id, '2023-01-01'::date, default_values_for_other_columns
FROM Location L
WHERE NOT EXISTS (
SELECT 1
FROM Filing F
WHERE F.location_id = L.location_id
AND F.filing_date = '2023-01-01'::date
);
INSERT INTO Filing (location_id, filing_date, other_columns)
SELECT L.location_id, '2023-01-01'::date, default_values_for_other_columns
FROM Location L
WHERE NOT EXISTS (
SELECT 1
FROM Filing F
WHERE F.location_id = L.location_id
AND F.filing_date = '2023-01-01'::date
);
But Im not sure how to approach it.
5 replies
DDeno
Created by bombillazo on 1/31/2024 in #help
Run `nvm` using Deno.Command
Hello, I am trying to run nvm from a Deno script using Deno.Command.
new Deno.Command('nvm', {
args: ['use'],
stderr: 'inherit',
stdin: 'inherit',
stdout: 'piped',
}).outputSync;
new Deno.Command('nvm', {
args: ['use'],
stderr: 'inherit',
stdin: 'inherit',
stdout: 'piped',
}).outputSync;
but I am getting the following error:
Failed to spawn 'nvm': No such file or directory (os error 2)
Failed to spawn 'nvm': No such file or directory (os error 2)
nvm was install with brew and I tried passing env: {PATH: Deno.env.get('PATH') but nothing works...
2 replies