Paul
Paul
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Paul on 5/25/2024 in #questions
How to manage external ids in my database
I'm storing Facebook ads in my database and I'm struggling to figure out whether to use external ids or internal ids. Relevant Stack: Using postgres, drizzle-orm, supabase Background: A facebook ad breaks down into several components: Facebook page, adCreative, ad, locations, 1) On a high level, I could ingest the facebook ad, break it down into it's component parts, add my own internal ids to each and reference each component with the internal ids; OR 2) I could rely mainly on the external ids as indexes (maybe primary key, maybe not), and link them based on these external ids Internal IDs: - Pros: My own data is protected from changes from Facebook - Cons: This makes inserting data in bulk way more sophisticated. Any ad will have the external ids, but I'll need to query for all the fields based on the external id in my database, check if they exist, if not, appending the corresponding internal id to the referencing table for each component. For example, if an ad references a page based on an internal id, I'll need to query for if that external pageId exists, if so, use that page's internalId and add it to the ad so that it is linked properly. External IDs: - Pros: Makes inserting into my database so much easier - Cons: Subject to changes from Facebook (realistically, it will be fine) as my ids are dependent on a third party's ids. I started using internal Ids because chatgpt said internal is better for more control, but the insertion process is really sophisticated and difficult to reason about. Can someone give me some insight, opinion, or recommendation on what they would do?
2 replies
TTCTheo's Typesafe Cult
Created by Paul on 5/15/2024 in #questions
how to use argon2 on vercel
There seems to be a persistent error when trying to use Argon2 on vercel. The project doesn’t deploy. Has anyone been able to get this working? The only way I made it work was running node 14 but that will be deprecated soon
2 replies
TTCTheo's Typesafe Cult
Created by Paul on 4/22/2024 in #questions
Is Prisma ORM still slow?
I’ve been using drizzle with postgres for a while. Wanted to use mongodb for another project with nextjs. I know prisma improved their data connection speed a bit a while back but is it still slow in real world usage or is it fine now?
11 replies
TTCTheo's Typesafe Cult
Created by Paul on 4/15/2024 in #questions
How can I subscribe to updates in an RSS feed?
I want to subscribe to changes on a shopify store’s RSS feed for their products. It seems extremely compute intensive to fetch the rss url every second or even every hour. I know RSS feeds are meant to be subscribed to so how can I make it so that I can get a trigger and update data in my database whenever the rss feed changes? Essentially how does feedly work under the hood? Ofc I can’t use feedly itself since I need to update my db based on updates in the rss feed
2 replies
TTCTheo's Typesafe Cult
Created by Paul on 9/29/2023 in #questions
Server Actions: Do you need to validate the session when calling Server Actions?
1) When using server actions, there's no need to use csrf tokens anymore right since no external party can call your server action. So it saves this whole step and complication right? 2) When using server actions, if I am storing my sessions in a database, do I still need to check if the user has an active session on every server action mutation? In the past you would need to since anyone can POST to your route. But now with server actions.... only you can call a function on your server right? Therefore, there's no need to validate any database changing function calls in the server action right? Or is that wrong, because someone can manipulate the javascript on the client side to still call the server action? If it still requires validation, I guess it would be a good idea to create a middleware-like server action that validates the user or throws before any mutation right?
3 replies
TTCTheo's Typesafe Cult
Created by Paul on 9/23/2023 in #questions
Do multiple server actions resolve to one lambda call or is it multiple?
A few questions on server actions in Nextjs 1) Can I have a server action call another server action? I don't see why not. 2) If so, does that result in two lambda functions being invoked or does it just treat it as a function calling another function and in terms of lambdas, it just becomes one lambda instance? Which I think so... 3) If it's just one lambda call, is there a difference between writing "use server" in the second function that the first server function calls? It's just symantics to ensure it's running on the server right? Doesn't really make that much of a difference and it's just safer to put it I guess but it doesn't neccessite that it becomes two lambda calls right? I also note that this is slightly different than the server only directive which protects env variables from being exposed on the client by accident. That is, writing use server is more for the developer to explicitly see that it's running on a server, and multiple server actions with use server can call each other and it's still one lambda call right?
2 replies
TTCTheo's Typesafe Cult
Created by Paul on 8/30/2023 in #questions
If recreating mailchimp like email marketservice with automations and campaigns - Kafka or RabbitMQ?
As per the title, super noob in terms of message broker services, but if recreating an email marketing service that should scale to many users, should one use kafka or is rabbitMQ sufficient to allow sending emails based on triggers, delays from past emails, and sending multiple emails at once. I assume part of the system architecture should involve using kafka or rabbitMQ and then the consumer still needs to use AWS cloudwatch to schedule the emails? I guess when thinking about it in this way though, maybe kafka or rabbitMQ aren't needed and I can schedule the emails in cloudwatch directly. But then other emails require delays from previous emails... Do I need kafka or rabbitMQ? If so, which one?
2 replies
TTCTheo's Typesafe Cult
Created by Paul on 4/20/2023 in #questions
next13 app dir - multiple route handlers in one folder?
Is it possible to have multiple route handlers in the app/api dir in the same folder? It seems like it would get out of control pretty fast if you need to create a folder for each route… Compared to trpc for example where you could have multiple routes under a common path. You can do so with appDir route handlers but you’d have so many more folders and files… is this the only way or can you avoid all these folders for each route?
7 replies
TTCTheo's Typesafe Cult
Created by Paul on 4/7/2023 in #questions
How to connect planetscale database using pgAdmin?
So I created a database in planetscale. Let's say the connection information looks like this...
database: mydb
username: myusername
host: aws.connect.psdb.cloud
password: mypassword
database: mydb
username: myusername
host: aws.connect.psdb.cloud
password: mypassword
I want to connect to the database using pgAdmin Under Add New Server > Connection > I enter in...
Host name/address: aws.connect.psdb.cloud
Port: 5432
username: myusername
password: mypassword
Host name/address: aws.connect.psdb.cloud
Port: 5432
username: myusername
password: mypassword
But it doesn't connect? What am I doing incorrectly? I also tried mysql://aws.connect.psdb.cloud/mydb?sslaccept=strict to no avail
4 replies
TTCTheo's Typesafe Cult
Created by Paul on 3/27/2023 in #questions
API's to update database - One POST path to update whole object or multiple?
I'm trying to understand what the common/best practice is for creating an API to update my database. Simple basic stuff, I'm just not familiar with what's common. If I have a Settings document/table and it has subsections like appearance, privacy, user_details, account_info, etc. Is it more common to... 1) Make the API mirror the prisma update function, so I'd create ONE REST API to the settings such that you can pass in any part of the settings and update the table? 2) Separate it out into the sections above so you have a REST API for each section so at least 4 POST routes to update the settings 3) Separate it out based on the UI, so there would maybe be 20 REST API's just to update each individual aspect of the settings? I like the idea of mirroring the prisma functions and just exposing it in a REST API (or trpc or whatever) but wanted to know if this was the typical approach
3 replies
TTCTheo's Typesafe Cult
Created by Paul on 3/10/2023 in #questions
Database structure for contacts in a CRM?
Let's say one is building a CRM and working on the database. Initially I thought each contact would be an entry in the contacts schema and every user who has that contact's email will have access to that entry. So anyone who adds [email protected] the db will query for that email and pull that data up. But then I need the ability to change that contact's data for that specific user. Say if they wanted to change their name or address or add a tag for that user. It doesn't make sense to update it for everyone, only this user, so then I'm thinking... okay maybe there are alt fields where different users can have custom key value pairs. So this contact schema will have a key and an array for custom values with the key being the userId. So something like... {name: [{user321: "bob"}, {user435: "bobby"}], } This is already sounding incorrect... That lookup seems like it'll take forever to pull all client fields for all clients of a user. So then I'm thinking, so each user needs to have a unique set of contacts and if I have 1000 customers and they each have [email protected] then there will be 1000 entries of [email protected] somewhere in my database? Can someone help me understand what the appropriate database structure/ schema is for something like this?
3 replies
TTCTheo's Typesafe Cult
Created by Paul on 3/4/2023 in #questions
Tree Shaking with Good DX
I'm trying to see if there's a solution where I can have a great developer experience (DX) (Ability to call elements as children of the parent like <Table.Row>) but also tree shake my primitive UI components. Given the following code...
const _Table = ({children}) => React.createElement("Table", {children});
const Head = ({children}) => React.createElement("Head", {children});
const Header = ({children}) => React.createElement("Th", {children});
const Body = ({children}) => React.createElement("TBody", {children});
// etc.

const Table = {Table: _Table, Head, Header, Body}
export default Table;
const _Table = ({children}) => React.createElement("Table", {children});
const Head = ({children}) => React.createElement("Head", {children});
const Header = ({children}) => React.createElement("Th", {children});
const Body = ({children}) => React.createElement("TBody", {children});
// etc.

const Table = {Table: _Table, Head, Header, Body}
export default Table;
When importing, I'd like to use it like so... (best DX)
return (
<Table.Table>
<Table.Head>
</Table.Head>
</Table.Table>
)
return (
<Table.Table>
<Table.Head>
</Table.Head>
</Table.Table>
)
My understanding is that importing it as the default won't tree-shake unused elements since I'm importing the whole Table object
import Table from "./Table";
import Table from "./Table";
But I also don't want to do something like this where I have to import all the elements at the top. This optimizes tree-shaking but decreases developer experience
import {TableTable, TableHead} from "./Table"

return (
<TableTable>
<TableHead>
</TableHead>
<TableTable>
)
import {TableTable, TableHead} from "./Table"

return (
<TableTable>
<TableHead>
</TableHead>
<TableTable>
)
The only alternative I can think of is...
// Table.tsx
// define the elements

const Table = {
Table: _Table,
Head,
Header,
Body,
TableRoot: _Table,
TableHead: Head,
TableHeader: Header,
TableBody: Body,
}
export const Table;
// Table.tsx
// define the elements

const Table = {
Table: _Table,
Head,
Header,
Body,
TableRoot: _Table,
TableHead: Head,
TableHeader: Header,
TableBody: Body,
}
export const Table;
Then when using it... you can choose to import it all or if you only need a small portion you can only import that element. But I think this somewhat defeats the whole tree shaking thing as it makes it much bigger in size when importing it all.
import Table from "./Table" // <- this makes it even bigger in size now I think
// or
import {TableRoot, TableHead} from "./Table"
import Table from "./Table" // <- this makes it even bigger in size now I think
// or
import {TableRoot, TableHead} from "./Table"
Open to different people's ideas and thoughts on what the best approach is.
2 replies
TTCTheo's Typesafe Cult
Created by Paul on 1/31/2023 in #questions
Does React Context/Providers inherently cause lower perf or only if it reloads a lot of components?
I'm creating a Switch component and want to pass the enabled state to the thumb component via a Provider. For some reason I have this belief that using Providers are a heavy solution that causes performance issues, but maybe that's only when it's at the top of the app and causes a ton of components to rerender. If I use a Provider in a switch, and say there are like 10-20 switches in a form, will that inherently cause performance issues because of all the context and providers created, or is a provider just another tool and it's fine to use if it doesn't rerender a hundred components on change? The alternative is to require the developer using the switch to pass the enabled prop down manually to the thumb. Is one more or less performance than the other or is this stuff negligible and I can use providers in primitive components (Switch, Button, Tooltips) and it won't effect performance much at all?
1 replies
TTCTheo's Typesafe Cult
Created by Paul on 1/21/2023 in #questions
Project Structure for Design System
I'm trying to build an app as a solo dev and I built a half-ass design system but not sure how to add it to the project, and curious how other people usually handle this. Inevitably whenever I'm building an app, I need to create components and then I need to view those components so Storybook becomes necessary. Should storybook be in that same project or should it be external? I'm too cheap to publish it to a private npm package, so the next option is having a monorepo (with turbo)... which is where I'm considering it right now With a monorepo, I guess I can put multiple different apps in that monorepo and leverage the same design system which is good. But if I create a mono repo, if the component styling ever changes, maybe I'll need to create a new monorepo? Also, it seems like a monorepo makes it hard to account for different theme colors of different apps unless it's baked into the design system - like a blue-ocean theme, but if you want a pink-flamingo theme then you'd have to add it to all the components... right? Overall just want to get some opinions on how people structure their apps if it's like a saas with a number of components needed.
3 replies
TTCTheo's Typesafe Cult
Created by Paul on 1/9/2023 in #questions
trpc - Calling a route inside itself
Based on the documentation here, you can call another route on the server side using:
const caller = route.createCaller({})
const caller = route.createCaller({})

However, if the route is within itself, is it possible to do so using the this keyword? If not, how can one call a route sibling?
import { z } from "zod";

import { router, publicProcedure } from "../trpc";

export const appRouter = router({
example: exampleRouter,
});

export const exampleRouter = router({
hello: publicProcedure.query(() => "Hello"),
world: publicProcedure.query(() => "World"),
greet: publicProcedure.query(function () {
const caller = this.createCaller({});
// const caller = appRouter.createCaller({}) ????
return caller.hello() + caller.world();
}),
});
import { z } from "zod";

import { router, publicProcedure } from "../trpc";

export const appRouter = router({
example: exampleRouter,
});

export const exampleRouter = router({
hello: publicProcedure.query(() => "Hello"),
world: publicProcedure.query(() => "World"),
greet: publicProcedure.query(function () {
const caller = this.createCaller({});
// const caller = appRouter.createCaller({}) ????
return caller.hello() + caller.world();
}),
});
3 replies
TTCTheo's Typesafe Cult
Created by Paul on 11/4/2022 in #questions
Nextjs+Expo(React Native) - Would trpc work?
I'm not sure about how uploading on Vercel works, but if I create an Expo app with NextJS for the web. If someone is on the phone and hits a route on the server, will that trigger the Vercel cloud function to run because the person on the phone is hitting that route?
3 replies
TTCTheo's Typesafe Cult
Created by Paul on 10/24/2022 in #questions
How to implement manual authentication without TTL entry
In MongoDB land, one way to create a user is creating a userToken when they sign up that automatically gets deleted by the database in expiresAt seconds if they don't confirm their account via email. What is the conventional way to accomplish this if there is no TTL functionality as it seems like Prisma doesn't support an expiresAt feature. I want to avoid a ton of userTokens accumulating in my DB if someone maliciously keeps signing up new accounts - besides rate limiting them and banning their ip etc. Just interested in db level cleaning solutions.. or alternatives to creating this userToken
2 replies
TTCTheo's Typesafe Cult
Created by Paul on 10/21/2022 in #questions
trpc.useQuery() doesn't have keys like with react-query?
I'm using trpc.useQuery() to get the user and was thinking of using a key like with react-query so I can query the cache for the user again later. However, from what I can see, it looks like there's no keys when using useQuery on trpc? If that's the case, is it good practice to store the user in context when using trpc? I wanted to avoid doing that if I can let react-query be my state manager. Ultimately, (1) does useQuery() have a key value cache function? If not, (2) is it bad to useContext to store the user?
// In react-query you can do...
const r = useQuery(args, ["user"]);

// In trpc, this doesn't work...?
const r = trpc.user.useQuery(args, ["user"]);
// In react-query you can do...
const r = useQuery(args, ["user"]);

// In trpc, this doesn't work...?
const r = trpc.user.useQuery(args, ["user"]);
2 replies
TTCTheo's Typesafe Cult
Created by Paul on 10/18/2022 in #questions
[Solved] Why does leetcode say “non-decreasing” and not “ascending”
Just going through leetcode questions and curious why it always say “non-decreasing” as opposed to “ascending”
6 replies