Julien Goux
12/07/2021, 10:22 AMJulien Goux
12/07/2021, 10:26 AMJulien Goux
12/07/2021, 10:27 AMDaniell
12/07/2021, 1:27 PMperp
12/07/2021, 1:33 PMIbad Shaikh
12/07/2021, 1:49 PMuser_id
which is linked to user model.
• There is a rating model which contains user_id
& post_id
& value
which stores the rating given on a specific post by a user.
• How could I get the average rating. I tried but couldn't found a solution for it.
Thanking in advance :)rdunk
12/07/2021, 3:07 PMYaakov
12/07/2021, 3:15 PMUNIQUE INDEX
with a where clause?
Model:
model UserRoles {
id Int @id @default(autoincrement())
user_id Int
role_id Int
facility_id Int?
// Mapping relations
user User @relation("UserRelation", fields: [user_id], references: [id])
role Role @relation("RoleRelation", fields: [role_id], references: [id])
facility Facility? @relation("FacilityRelation", fields: [facility_id], references: [id])
}
I want to add the following 2 indexes:
CREATE UNIQUE INDEX key_a ON user_roles (user_id, role_id)
WHERE facility_id IS NULL;
CREATE UNIQUE INDEX key_b ON user_roles (user_id, role_id, facility_id)
WHERE facility_id IS NOT NULL;
If Prisma does not allow me to do this, then what would be be the correct implementation for this?
Thank you!Stefano Giraldi
12/07/2021, 3:45 PMObjection.js
(Knex.js) to Prisma.
In Objection.js I've a custom method `verifyPassword`in User Model Class to check password
class User extends Model {
...
// Compares a password to a bcrypt hash, returns whether or not the password was verified.
async verifyPassword (password: string) {
return await bcrypt.compare(password, this.password)
}
...
}
Can I follow the same approach with Prisma or I need to create a custom function outside the model schema?Chris Bitoy
12/07/2021, 5:08 PMconst data = [
{
id: 1,
title: 'Top 5 Questions',
questions: [
{
// id -> is a composite key between the title id and question id
id: 10,
question:
'This is a question to be answered?',
checked: false,
input_type: 'radio',
answers: [
'Heard of it - never tried it before',
'Tried it once before',
'Buy it regularly',
'Curious to learn more',
],
},
]
terion
12/07/2021, 6:19 PMChidume Nnamdi
12/07/2021, 7:45 PMChris Bitoy
12/07/2021, 8:40 PMJin
12/07/2021, 8:53 PMJordansz
12/07/2021, 9:18 PMJordansz
12/07/2021, 9:19 PMJordansz
12/07/2021, 9:20 PMType '{ status: string; }' is not assignable to type '(Without<ScreeningCreateInput, ScreeningUncheckedCreateInput> & ScreeningUncheckedCreateInput) | (Without<...> & ScreeningCreateInput'''
Jordansz
12/07/2021, 9:20 PMDomenico Rutigliano
12/07/2021, 11:42 PMDavid
12/08/2021, 2:43 AMdb.decimal
.
if I set it as db.decimal(9,4)
, should it be like this <tel:1234567891234|123456789.1234>
or 12345.1234
?user
12/08/2021, 8:01 AMBarry
12/08/2021, 8:13 AMconst prisma = new PrismaClient();
prisma.$use(async (params, next) => {
console.log('runInTransaction: ' + params.runInTransaction)
const result = next(params);
return result;
})
async function test1() {
return await prisma.$transaction(async prisma => {
return await prisma.user.create({
data: {
name: '3333',
id: 3,
email: '<mailto:asa@gmail.com|asa@gmail.com>'
},
});
})
}
async function test2() {
return await prisma.$transaction(async prisma => {
const r = await prisma.user.update({
data: {
name: '4444',
},
where: {
id: 4
}
});
return r;
});
}
async function main() {
return await prisma.$transaction(async prisma => {
let t1 = await test1(); // throw an error
let t2 = await test2(); // put test2 in the first.
console.log(t1);
console.log(t2);
})
}
the record which id=3 has been existed in the database, so the code will be executed throw an error. no data in database will be changed.
but when I change the order test1() and test2() function.
async function main() {
return await prisma.$transaction(async prisma => {
let t2 = await test2(); // put test2 in the first.
let t1 = await test1(); // throw an error
console.log(t1);
console.log(t2);
})
}
the record which id=3 has been updated in database. although the test1 throw an error.
so this is the question, why the transaction is not rollback. I know I use nested transaction.
async function main() {
return await prisma.$transaction(async prisma => {
try {
// id = 3 existed in database so it will be an error
await prisma.user.create({
data: {
name: '3333',
id: 3,
email: '<mailto:asa@gmail.com|asa@gmail.com>'
},
});
} catch (error) {
}
await prisma.user.update({
data: {
name: '4444',
},
where: {
id: 4
}
});
})
}
I use try catch around the create(id=3). just in one transaction . the transaction also not rollback.
if remove try catch block the transaction works well.
It is not same with JAVA. in java no matter use try catch or not . the transaction will be rollback.
so I am very confused now.
does the transaction have hooks like "afterCommmit" "afterRollback"?Adrian
12/08/2021, 8:56 AMAdrian
12/08/2021, 8:58 AMAdrian
12/08/2021, 8:58 AMAdrian
12/08/2021, 9:21 AMAdrian
12/08/2021, 9:59 AMBenny
12/08/2021, 10:29 AMAaron Waller
12/08/2021, 11:51 AMError validating datasource `db`: the URL must start with the protocol `mysql://`
Can someone please look into my problem, I am stuck with this for 6 days now…
Seems like no one knows what the problem is, I even hired experts on Fiverr and codementor but no one is able to fix it.
https://stackoverflow.com/questions/70272207/node-js-graphql-api-stops-working-as-soon-as-i-deploy-it-error-validating-dataIradukunda Irenee
12/08/2021, 11:52 AM