Callum
07/20/2021, 10:05 AMfindMany
?Callum
07/20/2021, 10:08 AMThomas Morice
07/20/2021, 2:41 PMprotzman
07/20/2021, 6:34 PMconst usersByCountry = await prisma.user.groupBy({
by: ['country'],
count: {
country: true,
},
having: {
country: {
count: {
gt: 3,
},
},
},
})
}
so you could do something like aggregate by lat: {gt : whatever, lt: whatever} , lon: {gt : whatever, lt: whatever}
or something?prisma chobo
07/20/2021, 8:57 PMconst transaction = prisma.transaction.create({
data: {
audience,
description,
paymentMethodId: '',
type: 'TRANSFER',
balances: {
create: [
{
amount,
accountId: payeeId,
currency: 'GPT',
},
{
amount: amount * -1,
accountId: payorId,
currency: 'GPT',
},
],
},
transfer: {
create: {
payeeId,
payorId,
},
},
accounts: {
connect: [
{
id: '',
},
{
id: '',
},
],
},
},
});
And this is my schema for transaction and account:
model Transaction {
accounts Account[]
}
model Account {
transactions Transaction[]
}
This is my error:
Type '{ audience: AUDIENCE; description: string; paymentMethodId: string; type: "TRANSFER"; balances: { create: { amount: number; accountId: string; currency: "GPT"; }[]; }; transfer: { create: { ...; }; }; accounts: { ...; }; }' is not assignable to type '(Without<TransactionCreateInput, TransactionUncheckedCreateInput> & TransactionUncheckedCreateInput) | (Without<...> & TransactionCreateInput)'.
Type '{ audience: AUDIENCE; description: string; paymentMethodId: string; type: "TRANSFER"; balances: { create: { amount: number; accountId: string; currency: "GPT"; }[]; }; transfer: { create: { ...; }; }; accounts: { ...; }; }' is not assignable to type 'Without<TransactionUncheckedCreateInput, TransactionCreateInput> & TransactionCreateInput'.
Type '{ audience: AUDIENCE; description: string; paymentMethodId: string; type: "TRANSFER"; balances: { create: { amount: number; accountId: string; currency: "GPT"; }[]; }; transfer: { create: { ...; }; }; accounts: { ...; }; }' is not assignable to type 'Without<TransactionUncheckedCreateInput, TransactionCreateInput>'.
Types of property 'paymentMethodId' are incompatible.
Type 'string' is not assignable to type 'undefined'.
Dev__
07/20/2021, 9:13 PMevery
and some
? everything I use them they always do the opposite of what I expectDev__
07/20/2021, 9:21 PMmodel Buyer {
id
buyersToBuyerGroups BuyersToBuyerGroups[]
}
model BuyerGroup {
id
buyersToBuyerGroups BuyersToBuyerGroups[]
}
model BuyersToBuyerGroups {
buyerId
buyerGroupId
buyerGroup BuyerGroup @relation(fields: [buyerGroupId], onDelete: Cascade, references: [id])
buyer Buyer @relation(fields: [buyerId], onDelete: Cascade, references: [id])
}
so lets say there is two records inside the BuyersToBuyerGroups
buyerId buyerGroupId
1 32
1 12
so what I want with this query is I want to fetch all buyer groups where buyerId
is equal to x
prisma.buyerGroup.findMany({
where: {
buyersToBuyerGroups = {
every: {
buyerId: 1
}
};
}
})
I expect it to return only 2 buyerGroups
because of the where
but instead it returns me all rows expect those 2. am I misunderstanding every
or is this suppose to happen?
when i use some
it works as expected, I only get back 2 records...Chris Packett
07/21/2021, 3:11 AMArun Kumar
07/21/2021, 7:55 AMError querying the database: db error: ERROR: type "serial" does not exist
Paul
07/21/2021, 8:14 AMdb.damFile.updateMany({
data: {
deletedAt: DateTime.utc().toString(),
},
where: {
id: {
in: ids.join(",")
}
},
})
This obviously doesn't work. What's the best way to handle this use-case? I don't want to use a for loop and delete each one individually.
Note: I could use an execute raw and use a string array...
ThanksJohnyTheCarrot
07/21/2021, 8:30 AMType 'Prisma__our_record_formatClient<{ varOne: boolean; varTwo: boolean; }>' is missing the following properties from type 'OurRecordFormat': varOne, varTwo
Nichita Z
07/21/2021, 11:28 AMmodel Hashtag {
tag String @id
posts Post[]
}
And iām trying to count the relations like so:
include: { _count: { select: { posts: true } } },
And itās throwing the below error.. looks like prisma isnāt generating something correctly? Running prisma migrate dev tells me thereās nothing to generate šSubash Ganesh
07/21/2021, 12:29 PMBaris
07/21/2021, 12:56 PMnpx prisma migrate dev
returns this from the postgres container log:
2021-07-21 12:52:58.927 UTC [76] ERROR: relation "_prisma_migrations" does not exist at character 126
I have also defined the binaryTargets in the schema:
generator client {
provider = "prisma-client-js"
binaryTargets = ["native","linux-arm-openssl-1.1.x"]
}
Currently running node:16
on the docker container
When I am running a migration outside the docker container with
docker-compose run --publish 5555:5555 next npx prisma "migrate" "dev"
it throws an error that it could not reach the database:
Error: P1001: Can't reach database server at `test-postgres`:`5432`
The docker-compose for the db looks like this:
postgres:
container_name: 'test-postgres'
restart: unless-stopped
image: 'postgres:13'
platform: linux/arm64
ports:
- '15432:5432'
volumes:
- 'pgdata:/var/lib/postgresql/data/'
environment:
POSTGRES_PASSWORD: postgres
Scott
07/21/2021, 1:59 PMKindly
07/21/2021, 4:45 PMmodel User {
id String @id @default("")
habits UserToHabit[] @relation(name: "UserToHabit_User", fields: [id], references: [userId])
partnerHabits UserToHabit[] @relation(name: "UserToHabit_Partner", fields: [id], references: [partnerId])
league League @relation(fields: [leagueId], references: [id])
}
model UserToHabit {
id String @id @default("")
user User @relation(name: "UserToHabit_User", fields: [userId], references: [id])
partner User? @relation(name: "UserToHabit_Partner", fields: [partnerId], references: [id])
habit Habit @relation(fields: [habitId], references: [id])
habitId String
userId String
partnerId String?
@@unique([habitId, userId])
}
The relation from UserToHabit to User goes fine, as it goes from userId to id, but the other way around doesn't, as it goes from id to userId, but userId on UserToHabit isn't and can't be unique (habitId + userId is unique though). And I also can't remove the relation from User to UserToHabit because it doesn't let me.Gelo
07/21/2021, 6:48 PMWilliam Chantry
07/21/2021, 6:50 PMexecuteRaw
. Does anyone know if this is possible using executeRaw
? (thread)Paul
07/22/2021, 9:09 AMconst query = db.$executeRaw(
`
update DamFile
set deletedAt = ?
where id in (?)
`,
DateTime.utc().toString(),
ids.join(",")
)
const result = await db.$transaction([query])
console.log(result)
Can anyone catch what I am doing wrong? ThanksDavid
07/22/2021, 11:04 AMTypeError: prisma_1.default is not a constructor
š
anyone have any idea why?
basically I just make an index.ts
file and helper.ts
inside that and the content is:
helper.ts
import { PrismaClient } from '@prisma/client';
const client = new PrismaClient()
export default client;
index.ts
export { default } from './helper'
one of my backend app's index file:
import PrismaClient from 'my-library-name';
//just use the PrismaClient I imported like usual
I also tested by adding some console log in helper.ts
and index.ts
and when I run the backend app's, the console.log is printed before the error exception is appear.
---
tl;dr: I want to make a separate folder for the Prisma to shared into 3 different apps. But, I keep failed at importing the PrismaClient.Adam
07/22/2021, 3:20 PMprisma
https://www.twitch.tv/visualstudiouser
07/22/2021, 4:30 PMAlex Okros
07/22/2021, 5:14 PMprisma migrate deploy
in a self-contained environment without npm. Does anyone know how I can package the prisma cli with pkg
into an executable I can use in that environment?Chris Tsongas
07/22/2021, 8:22 PMCase
and CaseType
models which lead to CaseType
and CaseTypeType
types if I'm appending the word Type
to name my types. Awkward.
It was suggested to prefix type names with I
instead, but I don't use interfaces much mostly just types which I've heard someone's company prefixes with T
so maybe I'd do that, and prefix interfaces with I
and enums with E
?Chris Tsongas
07/22/2021, 8:24 PMWilliam Chantry
07/22/2021, 8:27 PMMelvin Gaye
07/22/2021, 9:10 PM.....
DELIMITER //
Drop proc if exists.....
Create proc...
....
END....
Running something like above to create a proc using workbench and it works. But when I run it using prisma.queryraw, prisma returns a syntax error.
Valid query that executes but prismatic has trouble with. Anyone ran into anything like this?Edward Baer
07/22/2021, 11:14 PMEdward Baer
07/22/2021, 11:15 PMconst mysql = require('mysql-await');
// Drop, and re-create Sequence Stored Procedure
const dropSomeProcedure = 'DROP PROCEDURE IF EXISTS someProcedure';
const createSomeProcedure = `
CREATE PROCEDURE someProcedure (
...
)
BEGIN
....
END
`;
const connectionParams = {
host: config.dbHost,
port: config.dbPort,
user: config.dbUsername,
password: config.dbPassword,
database: config.dbDatabase
};
const dbConn = mysql.createConnection(connectionParams);
await dbConn.awaitQuery(dropSomeProcedure );
await dbConn.awaitQuery(createSomeProcedure);
dbConn.end();
Edward Baer
07/22/2021, 11:15 PM