Tomathy
Tomathy
Explore posts from servers
PPrisma
Created by Tomathy on 11/6/2024 in #help-and-questions
Unknown argument...Available options are marked with ?.
Hello, I'm facing a problem while seeding my database. I have an implicit many-to-many relation table, and when creating one of the tables, I want to connect some existing rows from the other table into that one, like this:
const invoices: Prisma.InvoiceUncheckedCreateInput[] = [];
const list_aimis: {id: number}[] = faker.helpers.multiple(() => {
return { id: faker.number.int({min: 1, max: 500})}
}, {count: faker.number.int({min: 0, max: 3})}
)
if(list_aimis.length === 0){
invoices.push({
total_value: faker.number.bigInt({min: 10000, max: 1000000}),
invoice_date: faker.date.between({ from: '2020-01-01', to: '2024-12-31' }),
...
clientId: i + 1
})
} else {
invoices.push({
total_value: faker.number.bigInt({min: 10000, max: 1000000}),
invoice_date: faker.date.between({ from: '2020-01-01', to: '2024-12-31' }),
aimi: {
connect: list_aimis,
},
...
clientId: i + 1
})
}
const invoices: Prisma.InvoiceUncheckedCreateInput[] = [];
const list_aimis: {id: number}[] = faker.helpers.multiple(() => {
return { id: faker.number.int({min: 1, max: 500})}
}, {count: faker.number.int({min: 0, max: 3})}
)
if(list_aimis.length === 0){
invoices.push({
total_value: faker.number.bigInt({min: 10000, max: 1000000}),
invoice_date: faker.date.between({ from: '2020-01-01', to: '2024-12-31' }),
...
clientId: i + 1
})
} else {
invoices.push({
total_value: faker.number.bigInt({min: 10000, max: 1000000}),
invoice_date: faker.date.between({ from: '2020-01-01', to: '2024-12-31' }),
aimi: {
connect: list_aimis,
},
...
clientId: i + 1
})
}
The model for invoice:
model Invoice{
id Int @id @default(autoincrement())
client Client @relation(fields: [clientId], references: [id])
clientId Int
total_value BigInt
invoice_date DateTime
obs String?
aimi Aimi[]
...
}
model Invoice{
id Int @id @default(autoincrement())
client Client @relation(fields: [clientId], references: [id])
clientId Int
total_value BigInt
invoice_date DateTime
obs String?
aimi Aimi[]
...
}
I thought that maybe the reason for it was that connect didn't accept empty arrays, so I separated with the if clause. But i keep getting the error:
Unknown argument `aimi`. Did you mean `id`? Available options are marked with ?.
Unknown argument `aimi`. Did you mean `id`? Available options are marked with ?.
It also prints out the invoices array. Can anyone help me?
1 replies
PPrisma
Created by Tomathy on 10/23/2024 in #help-and-questions
SSL connection to supabase
Hello, I'm developing an application where the stack includes Prisma as an ORM and the database is hosted by supabase. The app is still in development, and I'm unsure how to make the connection between the development environment and the database be SSL encrypted. That, and how to enforce it also on a production environment. As a disclaimer, I'm using: Prisma + Sveltekit + Supabase. I've also tried to put sslmode=require on the database string, but it fails to establish a connection
18 replies
DTDrizzle Team
Created by Tomathy on 9/2/2024 in #help
No overload matches this call
I'm sorry that I'm already the 4th person with this sort of post, but the other posts didn't really help me out. I'm having an issue where it's sayig a certain attribute isn't in the type generated, but I don't see why not, and when I run the code it does work
await db.insert(clients).values({
name: faker.person.fullName(),
nif: faker.number.int({min: 100000000, max: 999999999}).toString(),
password: faker.internet.password(),
email: faker.internet.email(),
activity: client_activity[faker.number.int({min: 0, max: 2})],
obs: faker.helpers.arrayElement(['', faker.lorem.sentence()]),
services: faker.number.int({min: 1, max: services.length})
})
await db.insert(clients).values({
name: faker.person.fullName(),
nif: faker.number.int({min: 100000000, max: 999999999}).toString(),
password: faker.internet.password(),
email: faker.internet.email(),
activity: client_activity[faker.number.int({min: 0, max: 2})],
obs: faker.helpers.arrayElement(['', faker.lorem.sentence()]),
services: faker.number.int({min: 1, max: services.length})
})
Here's the schema:
//Clients table
export const clients = pgTable("clients",{
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }).notNull(),
nif: char("nif", { length: 9}).unique().notNull(),
password: bytea("password").unique().notNull(),
email: varchar("email", { length: 256}).unique(),
rf_taxrep: rfEnum("rf_taxrep"),
activity: activityEnum("activity").notNull(),
obs: text("obs"),
services: serial("services").references(() => service.id, {onDelete: "cascade"}),
})
//Clients table
export const clients = pgTable("clients",{
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }).notNull(),
nif: char("nif", { length: 9}).unique().notNull(),
password: bytea("password").unique().notNull(),
email: varchar("email", { length: 256}).unique(),
rf_taxrep: rfEnum("rf_taxrep"),
activity: activityEnum("activity").notNull(),
obs: text("obs"),
services: serial("services").references(() => service.id, {onDelete: "cascade"}),
})
Here's the error: No overload matches this call. Overload 2 of 2, '(values: { name: string | SQL<unknown> | Placeholder<string, any>; nif: string | SQL<unknown> | Placeholder<string, any>; password: SQL<unknown> | Buffer | Placeholder<...>; ... 5 more ...; services?: number | ... 2 more ... | undefined; }[]): PgInsertBase<...>', gave the following error. Object literal may only specify known properties, and 'name' does not exist in type '{ name: string | SQL<unknown> | Placeholder<string, any>; nif: string | SQL<unknown> | Placeholder<string, any>; password: SQL<unknown> | Buffer | Placeholder<...>; ... 5 more ...; services?: number | ... 2 more ... | undefined; }[]'.
12 replies