lelabo
lelabo
Explore posts from servers
TTCTheo's Typesafe Cult
Created by lelabo on 7/26/2024 in #questions
Handling Third-party lib client component that relies on ENV vars.
Hi, I am currently trying to add search on my project, and I stubbled upon a common scenario that I don't know how to handle yet... I am trying to use Meilisearch with react-instantsearch library. I have this snippet of code, from the doc:
"use client";

import { instantMeiliSearch } from "@meilisearch/instant-meilisearch";
import { InfiniteHits, InstantSearch, SearchBox } from "react-instantsearch";
import { env } from "~/env";

export const { searchClient } = instantMeiliSearch(
env.NEXT_PUBLIC_SEARCH_API_URL,
env.NEXT_PUBLIC_SEARCH_API_KEY,
);

export default function InstantSearchComponent() {

return (
// @ts-ignore
<InstantSearch indexName="steam-videogames" searchClient={searchClient}>
{/* @ts-ignore */}
<SearchBox />
{/* @ts-ignore */}
<InfiniteHits hitComponent={Hit} />
</InstantSearch>
);
}

function Hit({
hit,
}: {
hit: {
id: string;
image: string;
name: string;
description: string;
};
}) {
return (
<article key={hit.id}>
<img src={hit.image} alt={hit.name} />
<h1>{hit.name}</h1>
<p>${hit.description}</p>
</article>
);
}
"use client";

import { instantMeiliSearch } from "@meilisearch/instant-meilisearch";
import { InfiniteHits, InstantSearch, SearchBox } from "react-instantsearch";
import { env } from "~/env";

export const { searchClient } = instantMeiliSearch(
env.NEXT_PUBLIC_SEARCH_API_URL,
env.NEXT_PUBLIC_SEARCH_API_KEY,
);

export default function InstantSearchComponent() {

return (
// @ts-ignore
<InstantSearch indexName="steam-videogames" searchClient={searchClient}>
{/* @ts-ignore */}
<SearchBox />
{/* @ts-ignore */}
<InfiniteHits hitComponent={Hit} />
</InstantSearch>
);
}

function Hit({
hit,
}: {
hit: {
id: string;
image: string;
name: string;
description: string;
};
}) {
return (
<article key={hit.id}>
<img src={hit.image} alt={hit.name} />
<h1>{hit.name}</h1>
<p>${hit.description}</p>
</article>
);
}
- I could do this... but I prefer avoiding sensitive keys on client if possible. - I can create the searchClient props on the server, but I can't pass it to a client component. - I can't use the InstantSearch component server-side. How am I supposed to handle this type of Third-party problems where I have to create things client-side that depends upon sensitive keys?
24 replies
DTDrizzle Team
Created by lelabo on 7/18/2024 in #help
Insert line break in Postgres
I am trying to insert line breaks ('\n') into a text field in Postgres. I saw that I am supposed to do the following: https://stackoverflow.com/questions/36028908/postgresql-newline-character I would like to know if folks here have a solution without making a raw query to the database each time one of the field may store line breaks?
2 replies
DTDrizzle Team
Created by lelabo on 2/13/2024 in #help
How to drop a failed drizzle-kit push?
Hi, I made some changes to table (transformed some bigint("id", { mode: "number" }).notNull() to bigint("id", { mode: "number" }).primaryKey()). I tried to apply my changes with bun run dotenv drizzle-kit push:mysql as usual... And I got some errors:
Error: target: snacs.-.primary: vttablet: rpc error: code = Unknown desc = Check constraint 'id' is not found in the table. (errno 3821) (sqlstate HY000) (CallerID: q7b5b4s79a6trurkk7ej): Sql: "alter table snacs_food_attribute drop check id", BindVars: {REDACTED}
at PromiseConnection.query (/home/lelabo/DEV/SNACS/willitfodmap/node_modules/drizzle-kit/index.cjs:35481:26)
at Command.<anonymous> (/home/lelabo/DEV/SNACS/willitfodmap/node_modules/drizzle-kit/index.cjs:53292:33)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: undefined,
errno: 3821,
sql: 'ALTER TABLE `snacs_food_attribute` DROP CONSTRAINT `id`;',
sqlState: 'HY000',
sqlMessage: `target: snacs.-.primary: vttablet: rpc error: code = Unknown desc = Check constraint 'id' is not found in the table. (errno 3821) (sqlstate HY000) (CallerID: q7b5b4s79a6trurkk7ej): Sql: "alter table snacs_food_attribute drop check id", BindVars: {REDACTED}`
}
Error: target: snacs.-.primary: vttablet: rpc error: code = Unknown desc = Check constraint 'id' is not found in the table. (errno 3821) (sqlstate HY000) (CallerID: q7b5b4s79a6trurkk7ej): Sql: "alter table snacs_food_attribute drop check id", BindVars: {REDACTED}
at PromiseConnection.query (/home/lelabo/DEV/SNACS/willitfodmap/node_modules/drizzle-kit/index.cjs:35481:26)
at Command.<anonymous> (/home/lelabo/DEV/SNACS/willitfodmap/node_modules/drizzle-kit/index.cjs:53292:33)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: undefined,
errno: 3821,
sql: 'ALTER TABLE `snacs_food_attribute` DROP CONSTRAINT `id`;',
sqlState: 'HY000',
sqlMessage: `target: snacs.-.primary: vttablet: rpc error: code = Unknown desc = Check constraint 'id' is not found in the table. (errno 3821) (sqlstate HY000) (CallerID: q7b5b4s79a6trurkk7ej): Sql: "alter table snacs_food_attribute drop check id", BindVars: {REDACTED}`
}
So, I revert the changes, and try again to push some very minor change to another table to check if everything is ok. And I still get the same error. I don't know how I am supposed to drop the current cached mutation.
3 replies
DTDrizzle Team
Created by lelabo on 1/7/2024 in #help
Relations with multiple fields and references, or with constraints.
Lets say I have a table food and a table nutrient. The food table contains an id and a name. The nutrient table contains an id, a type and a name. I want to create a many-to-many relation about the food to their nutrients, so I did a third table: food-nutrient. The food-nutrient table as a foodId, a nutrientId and for now an amount. This setup seems to be doable with the many-to-many example, I did it just fine... I can now query food.foodNutrients and food.foodNutrients[number].nutrient. NOW, lets say, I want food.macros and food.micros which are the same relations but with a new constraint on nutrient.type. Is it doable and how? In MySQL, I would do this with a join (like the following) but I would rather use a relation if possible:
SELECT * FROM food_nutrient
JOIN nutrient ON nutrient.id = food_nutrient.nutrientId
WHERE foodId = 1 AND type = 'macro';
SELECT * FROM food_nutrient
JOIN nutrient ON nutrient.id = food_nutrient.nutrientId
WHERE foodId = 1 AND type = 'macro';
I saw that relation accept arrays in one function config arg for fields and references, I am playing with it right now, but did not figure how to do it yet, I would like to be able to specify something like a where.
9 replies
TTCTheo's Typesafe Cult
Created by lelabo on 1/2/2024 in #questions
How to make scripts in a t3-stack app (with tsx and t3-env)?
I am trying to create a scripts folder to run things along my website and create tools, test things and all. I tried tsx with success, until I needed the env to be available (thus involving t3-env). I am currently trying to do a small script to test inserting things in my database:
import { db } from "~/server/db";
import { food } from "~/server/db/schema";

await db.insert(food).values({
name: "Banana",
});
import { db } from "~/server/db";
import { food } from "~/server/db/schema";

await db.insert(food).values({
name: "Banana",
});
Until now, I did scripts that did not involve resources from the app but right now I would like to connect to my database but I get this error:
:x: Invalid environment variables: {
DATABASE_URL: [ 'Required' ],
DATABASE_HOST: [ 'Required' ],
DATABASE_USERNAME: [ 'Required' ],
DATABASE_PASSWORD: [ 'Required' ],
}
.../node_modules/.pnpm/@[email protected]_ophst5sms6obxk2veobtcst52a/node_modules/@t3-oss/core/index.ts:217
throw new Error("Invalid environment variables");
:x: Invalid environment variables: {
DATABASE_URL: [ 'Required' ],
DATABASE_HOST: [ 'Required' ],
DATABASE_USERNAME: [ 'Required' ],
DATABASE_PASSWORD: [ 'Required' ],
}
.../node_modules/.pnpm/@[email protected]_ophst5sms6obxk2veobtcst52a/node_modules/@t3-oss/core/index.ts:217
throw new Error("Invalid environment variables");
4 replies
DTDrizzle Team
Created by lelabo on 12/22/2023 in #help
Computed/derived fields in Drizzle Orm
Hi, I am new to Drizzle, so sorry if it is a stupid question, but while picking it up, browsing the docs, etc... I noticed something missing I had normally with many other ORMs in the past: computed fields (as Prisma call them, for example as what I mean). I don't know if I missed something, I didn't find an explanation in the introduction/philosophy of the docs... but I would like to know what the recommended path here and the stance of Drizzle on the subject (is it not implemented yet, not a desired feature because of complexity, performance, etc). I know I can always derive these states as I need them, but It is an approach I have seen in most ORM I used, so I am curious to know why, how, and all.
5 replies
TTCTheo's Typesafe Cult
Created by lelabo on 9/26/2022 in #questions
I need ideas for Data viz & Metrics framework in t3 stack ?
Hi, I created my app with the T3 stack (Prisma, next-auth, tRPC, Planetscale) and added axiom for logging and monitoring. It feels like I am missing something for data visualization... This stack allowed me to implement so much by letting great libs and services do all the heavy lifting. Right now, I would like the following : - a dashboard with the most critical metrics. - (maybe) a dashboard with curated data monitoring (to avoid getting in axiom every time). Before jumping into the code, I would like to know what and how others are doing regarding data viz... - Should I use another service like retool (any alternative ? I haven't found many)? - Best libraries? (For table, I am thinking about TanStack Table, but for graphs ?) - Recommendation and pitfalls?
7 replies