Matt
Matt
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Matt on 5/21/2024 in #questions
Can anyone tell me how to use environment variables for different environments within T3 please?
I have .env which is working fine. I want to use .env.development for when I dev and .env.product when I've built and deployed. I can't see anywhere where this can be set, I can see using this the variables don't switch as I expect and simply just default to .env. I've attempted to follow the Next docs to no avail. Am I missing something somewhere?
3 replies
DTDrizzle Team
Created by Matt on 4/21/2024 in #help
Struggling when changing tables relationships or columns
I find myself getting errors such as quite regularly [cause]: [ResponseError: SQLite error: no such table: main.old_push_business] { code: 'SQLITE_UNKNOWN', proto: { message: 'SQLite error: no such table: main.old_push_business', code: 'SQLITE_UNKNOWN' } } } It normally happens when I've changed a relationship or a column. I'll push the changes, it appears to be successful, I'll then try to run studio, which just gives me the loading spinner on the left where the columns normally are. I'll then try and push again and errors such as the above. This happens a lot, the work around I've found, at least locally, is to recreate the local db and push again which then seems to reset everything (I'm using LibSQL/Turso). Am I doing something fundamentally wrong that's causing these issues?
2 replies
DTDrizzle Team
Created by Matt on 4/18/2024 in #help
How do I filter with date in SQLite (Turso)
I can't find an answer in the docs but I have a timestamp defined in my schema like this updatedAt: text('updated_at').default(sql``(CURRENT_TIMESTAMP)``).notNull(), I'm trying to see whether this timestamp was in the last 24 hours but because the type is seen as a string it won't let me check it with Date and lt etc. What am I missing? Thanks.
6 replies
DTDrizzle Team
Created by Matt on 3/14/2024 in #help
Error when trying to create a unique constraint
I have this in my schema
export const businessImage = sqliteTable("business_image", {
id: integer('id').primaryKey({ autoIncrement: true }),
businessId: integer('business_id').notNull().references(() => business.id),
imageId: integer('image_id').notNull().references(() => image.id, { onDelete: 'cascade' }),
}, (t) => ({
unq: unique().on(t.businessId, t.imageId)
}));
export const businessImage = sqliteTable("business_image", {
id: integer('id').primaryKey({ autoIncrement: true }),
businessId: integer('business_id').notNull().references(() => business.id),
imageId: integer('image_id').notNull().references(() => image.id, { onDelete: 'cascade' }),
}, (t) => ({
unq: unique().on(t.businessId, t.imageId)
}));
I'm trying to create a unique constraint on the business and image ids but get an error
Type '{ unq: UniqueConstraintBuilder; }' is not assignable to type 'SQLiteTableExtraConfig'.
Property 'unq' is incompatible with index signature.
Type 'UniqueConstraintBuilder' is not assignable to type 'IndexBuilder | CheckBuilder | ForeignKeyBuilder | PrimaryKeyBuilder | UniqueConstraintBuilder'.
Type '{ unq: UniqueConstraintBuilder; }' is not assignable to type 'SQLiteTableExtraConfig'.
Property 'unq' is incompatible with index signature.
Type 'UniqueConstraintBuilder' is not assignable to type 'IndexBuilder | CheckBuilder | ForeignKeyBuilder | PrimaryKeyBuilder | UniqueConstraintBuilder'.
I thought I may have missed something so I lifted the example from the docs but get the same error. Example:
export const composite = sqliteTable('composite_example', {
id: int('id'),
name: text('name'),
}, (t) => ({
unq: unique().on(t.id, t.name),
}));
export const composite = sqliteTable('composite_example', {
id: int('id'),
name: text('name'),
}, (t) => ({
unq: unique().on(t.id, t.name),
}));
What am I missing?
3 replies
DTDrizzle Team
Created by Matt on 1/20/2024 in #help
Have I got inserts right for MySQL(Planetscale)?
I'm switching over to Drizzle from Prisma, just wanted to make sure I have inserts written correctly, specifically inserts with relationships, for example, this is inserting a business with an associated businessAddress, does that look right? Ctx is just TRPC.
await ctx.db.transaction(async (tx) => {
await tx.insert(businessTable).values({
businessName: input.businessName,
description: input.description,
email: input.email,
hasAgreedTerms: input.hasAgreedTerms,
userId: ctx.userId
});

const business = await tx.select({ businessId: businessTable.businessId }).from(businessTable).where(eq(businessTable.userId, ctx.userId));

const businessId = business[0]?.businessId;

await tx.insert(businessAddressTable).values({
addressOne: input.addressOne,
addressTwo: input.addressTwo,
city: input.city,
postCode: input.postCode,
countryId: input.countryId,
businessId: businessId
});
});
await ctx.db.transaction(async (tx) => {
await tx.insert(businessTable).values({
businessName: input.businessName,
description: input.description,
email: input.email,
hasAgreedTerms: input.hasAgreedTerms,
userId: ctx.userId
});

const business = await tx.select({ businessId: businessTable.businessId }).from(businessTable).where(eq(businessTable.userId, ctx.userId));

const businessId = business[0]?.businessId;

await tx.insert(businessAddressTable).values({
addressOne: input.addressOne,
addressTwo: input.addressTwo,
city: input.city,
postCode: input.postCode,
countryId: input.countryId,
businessId: businessId
});
});
Appreciate the input, thanks.
3 replies