oof2win2
oof2win2
Explore posts from servers
DTDrizzle Team
Created by oof2win2 on 10/9/2024 in #help
Cannot use pgEnum with aws aurora
Hi. I can't seem to use pgEnum with the AWS aurora adapter, as i keep getting the same error over and over. It seems weird, as intellisense doesn't say that the types are wrong at all when i am doing the update query, but pg returns an error ERROR: column "status" is of type "EmailStatus" but expression is of type text; Hint: You will need to rewrite or cast the expression.; Position: 31; SQLState: 42804
await db
.update(email)
.set({ status: "sending", messageId: res.MessageId })
.where(eq(email.emailId, msg.emailId))

export const emailStatus = pgEnum("EmailStatus", [
"none",
"sending",
"sent",
"cancelled",
])
export const email = pgTable(
"email",
{
emailId: serial().primaryKey(),
status: emailStatus().default("none"),
},,
)
await db
.update(email)
.set({ status: "sending", messageId: res.MessageId })
.where(eq(email.emailId, msg.emailId))

export const emailStatus = pgEnum("EmailStatus", [
"none",
"sending",
"sent",
"cancelled",
])
export const email = pgTable(
"email",
{
emailId: serial().primaryKey(),
status: emailStatus().default("none"),
},,
)
3 replies
CDCloudflare Developers
Created by oof2win2 on 9/30/2024 in #general-help
Migrating to a new account
Hey there. I want to migrate my current Cloudflare projects (domains, workers, D1, Stream) all to a new account. Is this possible without too much downtime and data loss?
1 replies
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
DTDrizzle Team
Created by oof2win2 on 8/20/2024 in #help
Joins with the Query API
Hi. I want to use .query to have nested queries for subitems, but i would also like to execute table joins within the API. Is it possible to achieve this somehow?
1 replies
DTDrizzle Team
Created by oof2win2 on 8/18/2024 in #help
drizzle-kit libsql extensions
hi. i want to ask if it is possible to add the extensions to drizzle-kit's libsql, mainly altering existing columns on tables. the issue is that drizzle-kit generates a migration with a generic message, where it doesn't specify which columns have changed so i can't even alter the columns myself. is there a way to add in an implementation of altering columns so that drizzle can use it, or at least getting drizzle to log the change that should be performed so that i can write the query myself?
/*
SQLite does not support "Creating foreign key on existing column" out of the box, we do not generate automatic migration for that, so it has to be done manually
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
https://www.sqlite.org/lang_altertable.html

Due to that we don't generate migration automatically and it has to be done manually
*/--> statement-breakpoint
/*
SQLite does not support "Creating foreign key on existing column" out of the box, we do not generate automatic migration for that, so it has to be done manually
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
https://www.sqlite.org/lang_altertable.html

Due to that we don't generate migration automatically and it has to be done manually
*/--> statement-breakpoint
1 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
CDCloudflare Developers
Created by oof2win2 on 4/14/2024 in #workers-help
how to setup rpc/entrypoints with workers for API access?
hi. so i have an api that is structured as below, and i was wondering how i would represent it within rpc or entrypoints. do i create a base entrypoint and make the rest RPC targets that can be used with a getter (option 1, doesn't seem too difficult), or can i create it with option 2 using classes on the base api class?
GET /reports
GET /reports/:id
POST /reports
GET /communities
GET /communities/:id
GET /reports
GET /reports/:id
POST /reports
GET /communities
GET /communities/:id
// option 1
const reportsRoute = await env.BACKEND.getReports()
const reports = await reportsRoute.getReport("id")

// option 2
const reports = await env.BACKEND.reports.getReport("id")
// option 1
const reportsRoute = await env.BACKEND.getReports()
const reports = await reportsRoute.getReport("id")

// option 2
const reports = await env.BACKEND.reports.getReport("id")
11 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
CDCloudflare Developers
Created by oof2win2 on 1/3/2024 in #general-help
image and video storage
so i want to create a image and video backup solution and host it somehow on cloudflare. is that realistic? i would quickly run out of R2 storage and would get to the paid tier. since i won't be reading the images very often (if at all), is there something else cloudflare offers that would suit me better?
3 replies
TTCTheo's Typesafe Cult
Created by oof2win2 on 11/12/2023 in #questions
How to use Vercel edge config within limits (usage and theory, not code)?
Hi. How would I go about using Vercel edge config in theory? Like there is a limit of 50k reads per month, and to me that seems like not a lot to be honest - that's 50 thousand page views on a single page that uses it - so you would basically divide that by the amount of pages you have if the traffic is approximately the same. Am I understanding these limits correctly?
2 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