Mateusz Stepaniuk
07/08/2022, 7:24 PMMateusz Stepaniuk
07/08/2022, 7:25 PMMateusz Stepaniuk
07/08/2022, 7:25 PMTom O'Neill
07/08/2022, 7:28 PMSchalk Neethling
07/08/2022, 8:12 PMMateusz Stepaniuk
07/08/2022, 8:14 PMSchalk Neethling
07/08/2022, 8:15 PMSchalk Neethling
07/08/2022, 8:18 PMconst prisma = new PrismaClient()
or should you instead have a util that returns the client if one does not already exist. I have many more questions like that 🙂Anthony Ma
07/08/2022, 8:52 PMCREATE TABLE `iot_device` (
`id` varchar(255) NOT NULL PRIMARY KEY,
`type` varchar(255) NOT NULL,
`location` varchar(255) DEFAULT NULL
);
CREATE TABLE `iot_device_status` (
`id` int(10) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
`device` varchar(255) NOT NULL,
`lost` tinyint(1) DEFAULT 0,
`created_at` datetime(6) DEFAULT current_timestamp(6)
);
Since iot_device_status
stores current and historic statuses from every iot_device
, I use this SQL script to retrieve the current status from every unique device:
SELECT *
FROM iot_device_status s
JOIN (SELECT device, MAX(created_at) AS max_date FROM iot_device_status GROUP BY device) sm
ON s.created_at = sm.max_date
AND s.device = sm.device;
In Objection JS, I can define this relationship in my entity and then referenced when needed:
export default class IOTDevice extends BaseEntity {
...
static relationMappings = () => ({
statusRelationship: {
relation: Model.HasOneRelation,
modelClass: IOTDeviceStatus,
join: {
from: "iot_device.id",
to: "iot_device_status.device",
},
modify: function (builder) {
builder
.alias("s")
.join(
IOTDeviceStatus.raw(
"(SELECT device, MAX(created_at) AS max_date FROM iot_device_status GROUP BY device) AS sm"
),
function () {
this.on("s.created_at", "=", "sm.max_date").andOn(
"s.device",
"=",
"sm.device"
);
}
);
},
},
});
}
const res = await IOTDevice.query().withGraphJoined("statusRelationship"); // returns the most recent status of each device
but as far as I can tell, there's no support for this kind of modification to relation. I would have to implement this outside of the client. Am I just overlooking something or am I correct in that prisma has no support for something like this?Zach
07/08/2022, 9:21 PMHalvor
07/08/2022, 9:34 PMHalvor
07/08/2022, 9:34 PMNorbert Takács
07/09/2022, 12:01 AM/app # npx prisma migrate deploy
Prisma schema loaded from prisma/schema.prisma
Datasource "db": SQLite database "rss_bot_database.db" at "file:./../config/rss_bot_database.db"
3 migrations found in prisma/migrations
Error: P3009
migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: <https://pris.ly/d/migrate-resolve>
The `init` migration started at 2022-06-09 13:06:17.104 UTC failed with the following logs:
/app #
When I try to use npx prisma migrate apply --applied "migration_name"
it says all the migrations are appliedRyan Thomas
07/09/2022, 3:29 AMhumblecoder
07/09/2022, 4:15 AMPrisma
JSON filter with array values? I’m trying:
findMany({
where: {
my_json_field: {
path: ['my','path'],
in: ['park','car','house'],
},
},
. . . but I’m receiving a TS error Type '{ path: string[]; in: any[]; }' is not assignable to type 'JsonNullableFilter'.
However, changing types doesn’t seem to matter.
The path contains a single text value. It is not an array. But I still want to see if the value is “IN” the provided array. I can do this with a raw query, but I’d rather have Prisma handle it in this case for further operations.
Is array filtering even possible with JSON values?Annu Singh
07/09/2022, 6:29 AMPatrick
07/09/2022, 12:11 PMconst [configDelete, billingDelete, userUpdate] = await prisma.$transaction([
prisma.config.delete({
where: { uid }
}),
prisma.billing.delete({
where: { uid }
}),
prisma.user.update({
where: { id: uid },
data: {
trialDays: 0
}
})
])
Halvor
07/09/2022, 12:24 PMAurora
07/09/2022, 3:53 PMprisma db push
to update my database, but this time I need to use prisma db migrate
. However, the CLI told me I nee to reset my database with data lost. How can I handle it? Thank you.Taofiq
07/09/2022, 9:51 PMTaofiq
07/09/2022, 9:52 PMprice _String[]_ @db.VarChar(255)
Andrei
07/10/2022, 8:46 AMmodel Tag {
id Int @id @default(autoincrement())
title String @db.VarChar
taggable_id Int
taggable_type String @db.VarChar
user_id Int
}
Dog
07/10/2022, 2:35 PMDunsin
07/10/2022, 10:22 PMBoo
07/10/2022, 10:26 PM--create-only
and adjust the column as generated always, and then run migrate dev
againBoo
07/10/2022, 10:27 PMChristophe Rudyj
07/11/2022, 12:32 PM['Kala','Modern Horizon']
Christophe Rudyj
07/11/2022, 12:35 PMMichael Jay
07/11/2022, 2:16 PMthis.prisma.role.update({
where: { id: incomingRole.id },
data: {
name: incomingRole.name,
permissions: {
deleteMany: {
id: { in: permissionsToDelete.map(permission => permission.id) }
},
create: permissionsToCreate.map(permissionName => {
return {
name: permissionName
}
})
}
}
})
But now I'm thinking that would instead delete and create actually Permission records, instead of deleting rolePermission records.
Update: I decided to just explicitly define the join. I really love the implicit join syntax, but reading through the Prisma docs, it seems like to use them in queries, I have to explicitly define them.MrDell
07/11/2022, 4:09 PMmodel Player {
id BigInt @id
createdAt DateTime? @default(now())
region String
country String
timezone String
Tournaments Tournament[]
}
and here i am trying to create the record in database.
await prisma.player.create({
data: {
id: Number(interaction.user.id),
region: region,
timezone: REGION[region][country]["timezone"],
country: country,
}),
Here's the error which is showed in terminal.
Error:
Invalid `prisma.player.create()` invocation:
Unique constraint failed on the fields: (`id`)
Can anyone tell me what's going wrong here? Any help would be appreciated!