Vilian
Vilian
Explore posts from servers
TtRPC
Created by Vilian on 8/4/2024 in #❓-help
How to query with async/await
I'm trying to initialise my react context store on mount with data coming from trpc. I'm using the t3 stack right now, and it's not immediately obvious on how to wait for the data to load before setting it in the store.. I'm using zustand and he is a snippet of my code
export const defaultInitState: State = {
user: null,
session: null,
permissions: {
user: false,
admin: false
},
tenants: [],
users: null
};

// Store
export const createUserStore = (initState: State = defaultInitState) => {
return createStore<Store>()((set) => ({
...initState,
reloadUsers: async () => {
const query = api.users.all.useQuery();
/// wait for query to be loaded and set the store's user data to the query data
},
reloadTenants: async () => {},

reset: async () => {
set(defaultInitState);

}
}));
};
export const defaultInitState: State = {
user: null,
session: null,
permissions: {
user: false,
admin: false
},
tenants: [],
users: null
};

// Store
export const createUserStore = (initState: State = defaultInitState) => {
return createStore<Store>()((set) => ({
...initState,
reloadUsers: async () => {
const query = api.users.all.useQuery();
/// wait for query to be loaded and set the store's user data to the query data
},
reloadTenants: async () => {},

reset: async () => {
set(defaultInitState);

}
}));
};
12 replies
DTDrizzle Team
Created by Vilian on 7/28/2024 in #help
Is it possible to create table during runtime?
I'm are trying to create a multi tenant application for my service. However, i'm unable to find relevant information on whether or not creating table during runtime is possible or not. The goal here would be to simply create new tables for a newly added tenant. The tables always have the same schema. My strategy is to simply suffix the newly created tables with a tenantId string
1 replies
DTDrizzle Team
Created by Vilian on 5/23/2024 in #help
Migrations not changing on adding notNull
Is it intended behaviour for migrations not to detect and react to the addition of a .notNull on some column ? Currently, my use case is that have a first migration that has created the table, but now the second migraiton (adding the notNull) doesn't actually create a migration.
2 replies
TTCTheo's Typesafe Cult
Created by Vilian on 8/28/2023 in #questions
Running migrations on startup
First of all, hey there, I hope you are doing well. My question as a new next js space/ecosystem is revolved around db migrations. I'm building an app that aims to be easily self-hostable, but currently, I'm unsure what the best approach is when it comes to applying and continuously rolling out new migrations. I would imagine that running some code before server next js server start is what I am looking for. Currently, my stack uses the default t3 stack, the only difference is that I use drizzle and turborepo. Any kind of suggestion/recommendation/pointer to a resource is greatly appreciated. Thank you for your time.
49 replies
TtRPC
Created by Vilian on 8/24/2023 in #❓-help
nextjs app router `fetchRequestHandler`'s createContext doesn't run.
Hey there, I have the following code:
// /src/app/api/trpc/[trpc]/route.ts
import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
import { appRouter } from '~/trpc/root';
import { ENV } from '~/env';
import { createTRPCContext } from '~/trpc/trpc';

const handler = (req: Request) =>
fetchRequestHandler({
req,
router: appRouter,
endpoint: '/api/trpc',
onError: ({ path, error }) => {
if (ENV.NODE_ENV !== 'development') return;
console.error(
`❌ tRPC failed on ${path ?? '<no-path>'}: ${error.message} `
);
},
createContext: createTRPCContext,
});

export { handler as GET, handler as POST };
// /src/app/api/trpc/[trpc]/route.ts
import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
import { appRouter } from '~/trpc/root';
import { ENV } from '~/env';
import { createTRPCContext } from '~/trpc/trpc';

const handler = (req: Request) =>
fetchRequestHandler({
req,
router: appRouter,
endpoint: '/api/trpc',
onError: ({ path, error }) => {
if (ENV.NODE_ENV !== 'development') return;
console.error(
`❌ tRPC failed on ${path ?? '<no-path>'}: ${error.message} `
);
},
createContext: createTRPCContext,
});

export { handler as GET, handler as POST };
24 replies
DTDrizzle Team
Created by Vilian on 8/19/2023 in #help
Query builder insert
What is the syntax for creating an insert query with the query builder ? There are some examples on the website showcasing select, but i'm looking for insert logic, which the query builder under drizzle-orm/sqlite-core is missing ( seems to only have select on the QueryBuilder)
9 replies
TtRPC
Created by Vilian on 4/1/2023 in #❓-help
context question
Why are the context examples only showing opinionated examples with next/react auth ? Also i find it very confusing that it is not mentioned in the docs what kind of arguments the context function is called with.
51 replies
TtRPC
Created by Vilian on 3/29/2023 in #❓-help
Quickstart not working
2 replies