Gaden
Gaden
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Gaden on 9/26/2024 in #questions
Drizzle turso configuration not working
Hi! No matter what i change in my schema, i get errors. Only if i drop all tables. i can successfully push again. Even just simple changes to schema doesn't work. I've tried multiple version of the t3 stack and have never got it working properly. What am i doing wrong? Here is an example of an error i get: terminal
@repo/db:db:push: TypeError: Cannot read properties of undefined (reading 'primaryKey')
@repo/db:db:push: at logSuggestionsAndReturn2 (/Users/gaden/Documents/GitHub/flashcards/node_modules/drizzle-kit/bin.cjs:72915:87)
@repo/db:db:push: at sqlitePush (/Users/gaden/Documents/GitHub/flashcards/node_modules/drizzle-kit/bin.cjs:74866:19)
@repo/db:db:push: at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
@repo/db:db:push: at async Object.handler (/Users/gaden/Documents/GitHub/flashcards/node_modules/drizzle-kit/bin.cjs:83724:9)
@repo/db:db:push: at async run (/Users/gaden/Documents/GitHub/flashcards/node_modules/drizzle-kit/bin.cjs:82064:7)
@repo/db:db:push: TypeError: Cannot read properties of undefined (reading 'primaryKey')
@repo/db:db:push: at logSuggestionsAndReturn2 (/Users/gaden/Documents/GitHub/flashcards/node_modules/drizzle-kit/bin.cjs:72915:87)
@repo/db:db:push: at sqlitePush (/Users/gaden/Documents/GitHub/flashcards/node_modules/drizzle-kit/bin.cjs:74866:19)
@repo/db:db:push: at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
@repo/db:db:push: at async Object.handler (/Users/gaden/Documents/GitHub/flashcards/node_modules/drizzle-kit/bin.cjs:83724:9)
@repo/db:db:push: at async run (/Users/gaden/Documents/GitHub/flashcards/node_modules/drizzle-kit/bin.cjs:82064:7)
packages/db/drizzle.config.ts
import { type Config } from "drizzle-kit";
import { env } from "@repo/env";

export default {
schema: "./schema.ts",
dialect: "sqlite",
driver: "turso",
out: "./migrations",
dbCredentials: {
url: env.TURSO_CONNECTION_URL!,
authToken: env.TURSO_AUTH_TOKEN!,
},
tablesFilter: ["flashcards_*"],
} satisfies Config;
import { type Config } from "drizzle-kit";
import { env } from "@repo/env";

export default {
schema: "./schema.ts",
dialect: "sqlite",
driver: "turso",
out: "./migrations",
dbCredentials: {
url: env.TURSO_CONNECTION_URL!,
authToken: env.TURSO_AUTH_TOKEN!,
},
tablesFilter: ["flashcards_*"],
} satisfies Config;
packages/db/package.json
{
"name": "@repo/db",
"module": "index.ts",
"type": "module",
"scripts": {
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push",
"db:studio": "drizzle-kit studio"
},
"dependencies": {
"@libsql/client": "^0.14.0",
"drizzle-orm": "^0.33.0"
},
"devDependencies": {
"@types/bun": "latest",
"drizzle-kit": "^0.24.2"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}
{
"name": "@repo/db",
"module": "index.ts",
"type": "module",
"scripts": {
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push",
"db:studio": "drizzle-kit studio"
},
"dependencies": {
"@libsql/client": "^0.14.0",
"drizzle-orm": "^0.33.0"
},
"devDependencies": {
"@types/bun": "latest",
"drizzle-kit": "^0.24.2"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}
packages/db/index.ts
import { createClient, type Client } from "@libsql/client";
import { drizzle } from "drizzle-orm/libsql";
import { config } from "dotenv";
import { env } from "@repo/env";
import * as schema from "./schema";

config({ path: ".env" });

/**
* Cache the database connection in development. This avoids creating a new connection on every HMR
* update.
*/
const globalForDb = globalThis as unknown as {
client: Client | undefined;
};

export const client =
globalForDb.client ??
createClient({
url: process.env.TURSO_CONNECTION_URL!,
authToken: process.env.TURSO_AUTH_TOKEN!,
});
if (env.NODE_ENV !== "production") globalForDb.client = client;

export const db = drizzle(client, { schema });
import { createClient, type Client } from "@libsql/client";
import { drizzle } from "drizzle-orm/libsql";
import { config } from "dotenv";
import { env } from "@repo/env";
import * as schema from "./schema";

config({ path: ".env" });

/**
* Cache the database connection in development. This avoids creating a new connection on every HMR
* update.
*/
const globalForDb = globalThis as unknown as {
client: Client | undefined;
};

export const client =
globalForDb.client ??
createClient({
url: process.env.TURSO_CONNECTION_URL!,
authToken: process.env.TURSO_AUTH_TOKEN!,
});
if (env.NODE_ENV !== "production") globalForDb.client = client;

export const db = drizzle(client, { schema });
2 replies
TTCTheo's Typesafe Cult
Created by Gaden on 7/19/2024 in #questions
Calling same TRPC endpoint from multiple components
Hey! I want to call the same trpc endpoint, with a refetch interval of 5 seconds, from multiple components. How do i make it so each component doesn't send the same request? Can i make the use the same responses somehow? Thanks in advance.
4 replies
TTCTheo's Typesafe Cult
Created by Gaden on 5/17/2024 in #questions
Paid (if allowed) - Help with laggy react frontend
hey :Peepsteroji_pepewavehappy: would anyone be interested in helping me out for like an hour or half pinpointing where my code is slow? i've made a fairly complex project, and the react frontend is a bit laggy and crunches ram. it's a frontend with a lot of realtime data coming in, so a bunch of renders is happening. if you can help me debug what exactly is happening im down to pay a little if allowed. paypal, crypto, revolut. whatever works for you
13 replies
TTCTheo's Typesafe Cult
Created by Gaden on 3/1/2024 in #questions
SSR with CSR after load
Hey! Is it possible to have SSR with CSR after the initial load? I'm using t3 with trpc and app router. The reason i want to do this, is since i want SSR for SEO compatibility, but the values are dynamically changing in realtime. How would i go about doing this? Do i have to make two separate components, and then render either one depending on if its server or client? Below is an example. The counter in my case, is a realtime updating value.
import { api } from "~/trpc/server";


export default async function Page({
params,
}: {
params: { contract: string };
}) {
const counter = await api.example.counter.query();

return (
<div className="relative h-full grow overflow-hidden">
{counter}
</div>
);
}
import { api } from "~/trpc/server";


export default async function Page({
params,
}: {
params: { contract: string };
}) {
const counter = await api.example.counter.query();

return (
<div className="relative h-full grow overflow-hidden">
{counter}
</div>
);
}
4 replies
TTCTheo's Typesafe Cult
Created by Gaden on 7/23/2023 in #questions
State manager for a realtime chat app?
Im developing a react native chat app. What state manager would you recommend? I've tried redux and valtio, and both seem fitting for this. There will be multiple active chats, group chats, and realtime messaging, so the state will be somewhat complex and dynamic. Whats your thoghts? ^^ Thanks in advance!
18 replies
TTCTheo's Typesafe Cult
Created by Gaden on 6/22/2023 in #questions
Upload image from server to uploadthing
Hello! My image is generated on the server, from user text input. Is it possible to upload the image directly from the server to uploadthing? It looks like to me uploadthing is only really used for users to upload, not the server? Thanks in advance!
10 replies
TTCTheo's Typesafe Cult
Created by Gaden on 4/11/2023 in #questions
Conditional trpc hook query
When calling a trpc hook, is there a way to only make it call, if the input is validated client side? Im using zod on server side. But sometimes it takes some time on client side before the data is valid. Example:
const {
data, isLoading, isError
} = reactApi.swap.getQuote.useQuery({
fromToken: debouncedInputToken,
toToken: debouncedOutputToken,
amount: parsedInput
})
const {
data, isLoading, isError
} = reactApi.swap.getQuote.useQuery({
fromToken: debouncedInputToken,
toToken: debouncedOutputToken,
amount: parsedInput
})
In this case im using debounced values. This results in a bunch of bad type zod errors before the values are correct. And conditionally rendering hooks gives errors. So how to only conditionally fetch trpc?
5 replies
TTCTheo's Typesafe Cult
Created by Gaden on 4/7/2023 in #questions
What statistics/analytics service to use?
Hey! Im building a crypto wallet. We wish to track how many transactions get sent over time, how much volume happens over time, how much our userbase grows over time etc. Is there a service i can use for this? Or is my best bet to just collect the data in a prisma db, and make my own admin dashboard with all the data.
21 replies
TTCTheo's Typesafe Cult
Created by Gaden on 12/2/2022 in #questions
Best state management for react chrome extensions?
Im looking into making a chrome extension. It will be handling a somewhat complex state, shared between background scripts, and the popup UI for the user. So my question is, how do i handle shared typesafe and persisting state across script in a chrome extension? Can't seem to find any good resources on this. Will i need to have different states in UI and background script, and then use some kind of bridge between them? Sounds like a environment that will slow development time drastically...
23 replies
TTCTheo's Typesafe Cult
Created by Gaden on 11/5/2022 in #questions
Is there a scaleable realtime type safe message broker?
Im currently using pusher. But it is not type safe. Or at least i havent found a way to make it type safe. Anyone have a better alternative?
3 replies