oof2win2
oof2win2
Explore posts from servers
KKysely
Created by oof2win2 on 9/25/2024 in #help
Implementing D1 batching (getting typed queries as input and returning typed InferResult)
Hi. I've wanted to get D1 batching to work, so I've tried doing as below. Functionally the code works, however I would like to get the proper type safety for this. Essentially I extend Kysely to add the executeBatch method and I want to infer the results for each of the individual queries. Is this possible?
9 replies
KKysely
Created by oof2win2 on 7/22/2024 in #help
why is WhereNode.where any operation node?
Hi. I'm working on a different query adapter (non-SQL), so I just want to ask why a WhereNode.where is simply any OperationNode and not a union of some operators (say boolean)
5 replies
KKysely
Created by oof2win2 on 6/28/2024 in #help
Accessing underlying methods on the client
Hi. I'm using libsql and I want to batch statements to be sent to the database. The underlying clients have these methods implemented, so I was wondering if it were possible to access these underlying methods from the Kysely class itself, or if it is necessary for me to write my own extension of the class to achieve this
7 replies
KKysely
Created by oof2win2 on 5/15/2024 in #help
Update on conflict clause
Hi. I need to use the on conflict clause in an update query within sqlite. I've searched the docs in mysql and it isn't present there. I created an example below for replication of the desired behavior. The only thing that I can think of is using the template sql`` operator from kysely, but is there a better way?
CREATE TABLE ReportCategory (
reportId TEXT,
categoryId TEXT,
PRIMARY KEY (reportId, categoryId)
);

INSERT INTO ReportCategory VALUES
("one", "hacking"),
("one", "griefing"),
("two", "griefing"),
("three", "hacking")
;

SELECT * FROM ReportCategory;
-- one|hacking
-- one|griefing
-- two|griefing
-- three|hacking

-- this statement should error
-- UPDATE ReportCategory SET categoryId="hacking" WHERE categoryId="griefing" ON CONFLICT IGNORE;

-- this will work
UPDATE OR IGNORE ReportCategory SET categoryId="hacking" WHERE categoryId="griefing";

SELECT * FROM ReportCategory;
-- one|hacking
-- one|griefing
-- two|hacking
-- three|hacking
CREATE TABLE ReportCategory (
reportId TEXT,
categoryId TEXT,
PRIMARY KEY (reportId, categoryId)
);

INSERT INTO ReportCategory VALUES
("one", "hacking"),
("one", "griefing"),
("two", "griefing"),
("three", "hacking")
;

SELECT * FROM ReportCategory;
-- one|hacking
-- one|griefing
-- two|griefing
-- three|hacking

-- this statement should error
-- UPDATE ReportCategory SET categoryId="hacking" WHERE categoryId="griefing" ON CONFLICT IGNORE;

-- this will work
UPDATE OR IGNORE ReportCategory SET categoryId="hacking" WHERE categoryId="griefing";

SELECT * FROM ReportCategory;
-- one|hacking
-- one|griefing
-- two|hacking
-- three|hacking
4 replies
KKysely
Created by oof2win2 on 4/9/2024 in #help
can kysely be extended with custom types within the database
hi. i would like to extend my database with custom types (a date type for sqlite) so that it is easier to work with. i would assume that conversion to sql would be easy since its just a stringify operation using sql template tags, but is there a way to automatically convert from the database results, i.e. parse a ISO string into a Date object?
5 replies
KKysely
Created by oof2win2 on 4/7/2024 in #help
building kysely makes the package size very large
hi. i'd be more than happy to figure this out because i like kysely a lot more than drizzle. the thing was that the package size was so much larger with drizzle. i made a repro here. when running bun build --minify --outfile, i get kysely to be 340.40kB whilst drizzle is 55.35kB, meanwhile the functional code besides the database is identical
78 replies
KKysely
Created by oof2win2 on 2/18/2024 in #help
Querying on jsonArrayFrom
Hi. So i need to fetch posts with comments from a database that are written by a set group of authors and have comments that are written by a set group of people. How would I accomplish this with sql? The best thing I can think of is fetch all posts and comments where the posts are written by the authors, and then do further clientside filtering on the comments - but is there a way to do this with the sql itself?
7 replies
KKysely
Created by oof2win2 on 2/7/2024 in #help
transforming database values to JS values (dates in sqlite)
hi. is it possible to transform database values with any driver into any JS value? such as integers to timestamps on specified columns? i want to do this for sqlite and other databases but idk how
4 replies
KKysely
Created by oof2win2 on 1/21/2024 in #help
Support for D1 batching
Hi. I'm wondering about support for batching statements with Cloudflare's D1 batching, similar to libsql's batching - i.e. multiple statements are sent and processed at once similar to a transaction, except it all occurs within the database driver itself. Can I somehow go about extending kysely or my dialect to add support for this? I.e. some dialect-specific functions i guess?
4 replies
KKysely
Created by oof2win2 on 11/4/2023 in #help
Using a custom HTTP driver for Kysely
Hi. I want to use neondb as my database. The issue is that I can't create a PostgresDialect class instance from the default provided pool, as that uses websockets - which is not what I want. Is there a way to tell Kysely to use HTTP connections (such as with kysely-planetscale), or do I need to make the driver myself?
7 replies
KKysely
Created by oof2win2 on 6/9/2023 in #help
Prisma-kysely generator converts boolean to a number
Hi, so using prisma-kysely, the generated type for a prisma Bool appears to be a number for some reason. Is this correct?
4 replies
KKysely
Created by oof2win2 on 6/9/2023 in #help
Is there a way to not have as many Selectable<> generics?
Hi. I'm using prisma-kysely to generate my Kysely types, and it generates them with the Generated generic. I therefore need to use the Selectable generic to change it to the return type of what is selected when I want to use the type. Is there a way to avoid using it so often?
13 replies
KKysely
Created by oof2win2 on 5/27/2023 in #help
Achieve Prisma-like nested selects
Hi. Is it possible to achieve Prisma-like nested selects with Kysely? I have the following code and it has the type below in Prisma, but I'm not sure how to achieve the same in Kysely without just doing an additional select * from CommitteeCountry where id in (select id from Committee) or something along those lines and then mapping the results in JS
const data = await prisma.Committee.findMany({
include: {
countries: true,
},
})

{
id: number
...

countries: {
id: number
committeeId: number
...
}[]
}
const data = await prisma.Committee.findMany({
include: {
countries: true,
},
})

{
id: number
...

countries: {
id: number
committeeId: number
...
}[]
}
15 replies
KKysely
Created by oof2win2 on 5/27/2023 in #help
Why is numUpdatedRows a BigInt?
Hi. I'd just like to ask as to why the number of updated rows in Kysely is a BigInt, as for all other ORMs that I've seen, it's just a normal number. Was there any reason for this decision?
22 replies