Amit
Amit
Explore posts from servers
DTDrizzle Team
Created by Amit on 8/13/2024 in #help
MYSQL iterator() streaming hangs randomly
https://orm.drizzle.team/docs/select#iterator I am trying to stream results using the iterator feature. But the iteration seems to hang randomly after some time. Any idea what could be leading to this or if it can be a bug?
const iterator = await db.select().from(users).iterator();
for await (const row of iterator) {
console.log(row);
// query another table
}
const iterator = await db.select().from(users).iterator();
for await (const row of iterator) {
console.log(row);
// query another table
}
1 replies
DTDrizzle Team
Created by Amit on 3/15/2024 in #help
on cascade delete issue with multiple foreign keys and migrations
I have a mysql schema like this,
export const table1 = mysqlTable('table1', {
id: int('id').primaryKey().autoincrement()
});

export const table2 = mysqlTable('table2', {
id: int('id').primaryKey().autoincrement(),
fk1: int('fk1')
.references((): AnyMySqlColumn => table1.id)
.notNull(),
fk2: int('fk2')
.references((): AnyMySqlColumn => table1.id)
.notNull()
});
export const table1 = mysqlTable('table1', {
id: int('id').primaryKey().autoincrement()
});

export const table2 = mysqlTable('table2', {
id: int('id').primaryKey().autoincrement(),
fk1: int('fk1')
.references((): AnyMySqlColumn => table1.id)
.notNull(),
fk2: int('fk2')
.references((): AnyMySqlColumn => table1.id)
.notNull()
});
I ran the generate command and then added { onDelete: 'cascade' } to both fk1 and fk2. When i ran generate again, the generated migration file only contains statement for updating cascade delete for fk1.
// 0001_neat_thena.sql
ALTER TABLE `table2` DROP FOREIGN KEY `table2_fk1_table1_id_fk`;
--> statement-breakpoint
ALTER TABLE `table2` ADD CONSTRAINT `table2_fk1_table1_id_fk` FOREIGN KEY (`fk1`) REFERENCES `table1`(`id`) ON DELETE cascade ON UPDATE no action;
// 0001_neat_thena.sql
ALTER TABLE `table2` DROP FOREIGN KEY `table2_fk1_table1_id_fk`;
--> statement-breakpoint
ALTER TABLE `table2` ADD CONSTRAINT `table2_fk1_table1_id_fk` FOREIGN KEY (`fk1`) REFERENCES `table1`(`id`) ON DELETE cascade ON UPDATE no action;
Is this a bug ?
1 replies
TTCTheo's Typesafe Cult
Created by Amit on 4/14/2023 in #questions
devalue vs superjson
I can see that in TRPC documentation, superjson is mostly suggested as the transformer. I recently found out about devalue and this comparison: https://github.com/Rich-Harris/superjson-and-devalue. It seems there was a security issue with devalue. As far as I know, the issue appears to have been fixed. So, are there any reasons to use superjson instead of devalue now?
2 replies
TTCTheo's Typesafe Cult
Created by Amit on 4/10/2023 in #questions
go like async channels in node
What are some of the good options to have go like channels in node. So far I have used, 1. https://www.npmjs.com/package/async-channel (facing weird bugs -- unhandled promise rejection randomly, not sure if it's a bug in my code or the library itself, need more time investigating). 2. Implemented something with eventemitter and async iterator. 3, Briefly tried to implement it using Node streams but it got too complex for what i think should be simple. Also was not sure how to make it work with typescript. 4. Saw this, https://deno.land/x/async_channels@v1.0.0-rc8 5. Saw this https://pedrocattori.dev/blog/go-like-channels-in-10-lines-of-javascript Is there something better or more mature available in the node ecosystem to work with this pattern ?
2 replies
TTCTheo's Typesafe Cult
Created by Amit on 4/10/2023 in #questions
trpc alternatives like zodios, ts-rest
I am using TRPC and really liking the developer experience. I recently got to know about zodios, ts-rest etc. I believe they provide a similar experience but play along more nicely with normal REST api conventions. To use TRPC endpoints from non-typescript backends, we would need to use something like OpenApi adapters. I don't know if the adapters are stable. What are your thoughts on this ? The feeling that i get about these new alternatives is along the lines of, anything that uses a lot of typescript inference will eventually run into scale problems. (slow inference, needing to restart typescript). I even saw some github issues mentioning the typescript inference limit was reached or something. I believe TRPC should be the least risky option when compared to the alternatives.
4 replies
TTCTheo's Typesafe Cult
Created by Amit on 2/27/2023 in #questions
nextjs API routes become unresponsive in dev mode
I am encountering a problem where the API routes become completely unresponsive in dev mode. To demonstrate this, I have created this minimal example. https://github.com/amit13k/create-t3-app-example2 The changes that were made to the generated t3 app are as follows, 1. top level await was enabled
webpack: (config, options) => {
config.experiments = {
"topLevelAwait": true,
"layers": true
};
return config;
},
webpack: (config, options) => {
config.experiments = {
"topLevelAwait": true,
"layers": true
};
return config;
},
2. There is an api route called example which uses an export named "someValue" from "src/lib/someModule". 3. In the file "someModule", "someValue" is exported similarly to how prisma get's exported to prevent problems related to multiple instances during npm run dev. "/api/example" works fine the first time. But if we make some changes to src/pages/index.tsx which leads to fast refresh, /api/example becomes unresponsive. I am not entirely sure why this happens, but it definitely seems related to node global and the top level await being used. If I don't use an async function with top-level await (rest everything being the same), this problem doesn't happen. Trying to understand why this happens and looking for suggestions on how to make this work with async functions.
1 replies
TTCTheo's Typesafe Cult
Created by Amit on 2/12/2023 in #questions
Good way to run single file script with NextJS
Is there a good way to run single file script without starting the webserver in a nextjs project and utilizing prisma/other server side features? Similar to django management commands (if you are familiar with python/django). I have tried using tsx but I am running into many small issues mostly related to tsconfig/module importing etc.
4 replies
TTCTheo's Typesafe Cult
Created by Amit on 1/26/2023 in #questions
using prisma with next 13 app dir
I have just started exploring prisma and next 13. I have read on the Prisma official website, "React Server Components are currently an experimental feature and are not yet ready for production usage! We are collaborating with the React team to ensure that the react-prisma package will be kept up-to-date". But, I can import the PrismaClient from @prisma/client in the page.ts(without 'use client'; so I hope it's a server component) and something like const posts= await prisma.posts.findMany() works. I might need to understand a lot of concepts better here. Is this the right way to use prisma inside the next 13 app directory. This way, I can skip rest/graphql/trpc for a significant portion of the web app(and also improve SEO/lighthouse metrics I guess).
2 replies