Richard E
Richard E
Explore posts from servers
NNuxt
Created by Richard E on 4/25/2024 in #❓・help
Is it possible for any env variables to be leaked from the nitro server package?
After build I can see my db connection info from the env variable embedded into the node-server.mjs file. Is there any way at all that could be surfaced to the client if all my code that uses that variable is in a server route such as trpc calls?
1 replies
DTDrizzle Team
Created by Richard E on 3/28/2024 in #help
How can I convert a null value to integer in a select?
I am doing a left join so joined table may contain null fields. In this case I have a player.ranking field that if null I want to default to 9999. I've tried numerous ways but nothing is working:
const data = await db.select({
player_name: tournament_snapshot_detail.player_name,
ranking: sql<number>`ISNULL(${player.ranking},9999)`
}).from(tournament_snapshot_detail)
.leftJoin(player, eq(tournament_snapshot_detail.player_name, player.name))
.where(and(
eq(tournament_snapshot_detail.snapshot_id, snapshots[0].value ?? 0),
eq(tournament_snapshot_detail.amateur, false)))
.orderBy(player.ranking)
const data = await db.select({
player_name: tournament_snapshot_detail.player_name,
ranking: sql<number>`ISNULL(${player.ranking},9999)`
}).from(tournament_snapshot_detail)
.leftJoin(player, eq(tournament_snapshot_detail.player_name, player.name))
.where(and(
eq(tournament_snapshot_detail.snapshot_id, snapshots[0].value ?? 0),
eq(tournament_snapshot_detail.amateur, false)))
.orderBy(player.ranking)
4 replies
DTDrizzle Team
Created by Richard E on 3/7/2024 in #help
Is there a way to set foreign key on a bulk insert?
Apologies if this is a stupid question but I need to know if I'm missing something obvious. I have two tables where the second one has a foreign key relationship to the other, standard master/detail setup. After I insert the master records, call the entity Pool I return the new id and then I loop through an array of detail records and set that foreign key pool_id to the newly acquired id and then do a batch insert of those detail records PoolTeam like so
async createPoolTeamPlayers(input: CreatePoolTeamPlayer[]): Promise<void> {
await db.insert(pool_team_player).values(input)
}
async createPoolTeamPlayers(input: CreatePoolTeamPlayer[]): Promise<void> {
await db.insert(pool_team_player).values(input)
}
Is there any way I can specify the master record id in this insert statement without having to previous loop through the array setting the pool_id property? It it possible to do this master/detail insert in a single call with Drizzle? It works the way I have it but just seems wrong to do it this way.
2 replies
NNuxt
Created by Richard E on 1/15/2024 in #❓・help
Getting 404 after app.config.ts change
Not sure if anyone else if getting this but I've been making changes to app.config.ts in dev mode and Nitro is triggering a page reload but I'm then getting a 404 of that page. If I wait a little while I can refresh the page and everything is fine. Here is what I'm doing if you can reproduce. 1. Using the nuxt-ui-pro/saas project template here, https://github.com/nuxt-ui-pro/saas 2. Creating the initial site off the template with npx nuxi init -t github:nuxt-ui-pro/saas 3. Opening the code up with VS Code, then starting the dev server with pnpm run dev and everything looks fine 4. In the content subfolder, edit the 0.index.yml file and change the hero title and you should see everything hot reloads. I have developer tools open for my browser with Disable cache ticked because if I don't I get some cached content from another site I had on localhost:3000 5. Now if I edit the app.config.ts file and change anything or even just save what is already there Nitro sees a change and reloads that file, but in the brower I get the following:
{
"statusCode": 404,
"statusMessage": "Cannot find any path matching /.",
"stack": []
}
{
"statusCode": 404,
"statusMessage": "Cannot find any path matching /.",
"stack": []
}
6. If I refresh my browser page then I get the full page with changes Any ideas? This is killing any productivity I might have in editing the site and really annoying.
4 replies
DTDrizzle Team
Created by Richard E on 1/10/2024 in #help
Is there a way to introspect with specific order?
When I generate my schema file with introspect:pg the tables are not in any order was far as I can see. They are probably in whatever order I created them but it's very messy with a lot of tables. Is there any way to put some kind of order to this?
3 replies
DTDrizzle Team
Created by Richard E on 12/6/2023 in #help
Infer select that includes a foreign key object collection?
If I have a query such as the following:
const result = await db.query.users.findMany({
with: {
posts: true
},
});
const result = await db.query.users.findMany({
with: {
posts: true
},
});
how can I use something like
type SelectUser = InferSelectModel<typeof users>;
type SelectUser = InferSelectModel<typeof users>;
to infer users with posts included?
2 replies