Philipp Klein
08/08/2022, 1:45 PM... where: {in: [{columnA: 1, columbB:2}, {columnA: 15, columbB:17}]} ...
Robert Woods
08/09/2022, 4:36 PMexport type LessonsCompleted = {
id: number
watchedVideo: boolean
readText: boolean
completionDate: Date | null
userId: string
lessonId: number
}
has a relation to Lesson
, however the generate command doesn't add that to the client. I can manually add lesson: Lesson
to my LessonsCompleted
model and I'm able to select the lesson as needed, however when I regenerate my client, that is undone and the field is no longer on the model. Is there anyway to get around this? Am I misunderstanding something?Rich Starkie
08/11/2022, 11:36 AMconst shelfContents = await prisma.libraryShelves.findUnique({
where: {
shelfId: id
},
include: {
shelfRelease: {
include: {
releaseArtists: true,
releaseRecordLabel: true,
releaseFormats: true,
releaseStyle: true,
releaseGenres: true,
releaseCurrentLocation: true,
}
},
},
});
every time I add a select: {}
statement to any of the included tables, or even to libraryShelves
under the where@{}
the whole statement falls apart and just returns the clientversion information
can anyone please advise?Rich Starkie
08/11/2022, 12:42 PMwhere
conditions ...
eg:
where:{
shelfId: id,
shelfPublished: true
}
shelfPublished is a Boolean (probably obvious but thought worth mentioning)Rich Starkie
08/11/2022, 6:55 PMRich Starkie
08/11/2022, 6:57 PMwhere:{
shelfId: id,
shelfPublished: true
}
Expected Behaviour ...
To Filter by BOTH where
statements
Actual Behaviour ...
returns the following
"client-version" : "4.1.xxxx"
Philipp Klein
08/12/2022, 11:56 AMprisma.foo.findMany({
where: {
data: {
meta: Prisma.AnyNull,
},
},
})
I get
Object literal may only specify known properties, and 'data' does not exist in type 'FooWhereInput'
if i try to do:
prisma.foo.findMany({
where: {
meta: Prisma.AnyNull,
},
})
I get:
[tsserver 2322] [E] Type 'AnyNull' is not assignable to type 'JsonNullableFilter'.
What am I missing?Luan Rodrigues
08/12/2022, 3:05 PMJeremy Hinegardner
08/12/2022, 4:43 PMRich Starkie
08/13/2022, 8:01 AMcreateMany
with many relationships, which I know according to the prisma docs you can't do.
I have been following the docs on the prisma site, it does the first (main) CreateMany
then for any of the others in the same bit of script, I get an Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
can anyone please advise how I should do the bulk import?
I can post code snippet if it becomes necessary, and I'm happy to do a Live Share in VSC
or a Code With Me in WebStorm
if it is easier
At this stage of the project, I can, just about get away with refactoring the data, but that would be a total pain in the ass and would need refactoring of other parts of the project that are completed ... possible, but impracticalIgnacio Velasco
08/16/2022, 2:48 PM$queryRaw
, my stored procedure returns two results, but I am only getting the last one.
Is there any way to get both values?Guillermo David
08/17/2022, 3:14 PMGuillermo David
08/17/2022, 3:15 PMwhere: {
firstName: { search: 'word' },
lastName: { search: 'word' },
} // this is an error
Guillermo David
08/17/2022, 3:16 PMDávid Korečko
08/18/2022, 10:16 AMDávid Korečko
08/18/2022, 10:18 AMDávid Korečko
08/18/2022, 10:18 AMGustavo
08/19/2022, 3:58 AMschema.prisma
e.g.
- project_folder
-- migrate.js
-- src
---- index.ts
---- packages
------- package_1
---------- index.ts
---------- prisma
------------- client
------------- migrations
------------- schema.prisma
------- package_2
---------- index.ts
---------- prisma
------------- client
------------- migrations
------------- schema.prisma
package_1 > prisma > schema.prisma
looks like:
generator client {
provider = "prisma-client-js"
previewFeatures = ["interactiveTransactions"]
output = "./client"
}
datasource db {
provider = "mysql"
url = env("ORGANISATION_CONTEXT_DATABASE_URL")
}
ORGANISATION_CONTEXT_DATABASE_URL
is always the same for a given env (dev, prod, etc...)
package_2 > prisma > schema.prisma
looks like:
generator client {
provider = "prisma-client-js"
previewFeatures = ["interactiveTransactions"]
output = "./client"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
DATABASE_URL
changes depending the user making a request.
Everything locally works just fine.
The issue I have is at the moment of applying migrations when deploying through github actions. At the moment I'm testing the following.
Whenever everything has been deployed run the command:
ci.yml
- name: "Run migrations"
run: yarn migrate
package.json
{
"scripts": {
"migrate": "node migrate.js"
}
}
migrate.js
process.env.ORGANISATION_CONTEXT_DATABASE_URL = 'postgressql://....'
const organisationContextSchema='./src/packages/package_1/prisma/prisma.schema'
const cmd1 = spawnSync('npx', ['prisma', 'generate', `--schema=${organisationContextSchema}`]);
const cmd2 = spawnSync('npx', ['prisma', 'migrate', 'deploy', `--schema=${organisationContextSchema}`]);
// HERE IS WHERE PROBLEMS HAPPEN!!!! :(
const orgContDbClient = new PrismaClient({
datasources: { db: { url: process.env.ORGANISATION_CONTEXT_DATABASE_URL } },
});
console.log('connected! Fetching orgs...');
const dbOrgs = await orgContDbClient.organisation.findMany();
console.log('dbOrgs: ', dbOrgs);
Error:
Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
😞Pascal Sthamer
08/19/2022, 3:49 PMError querying the database: Server error: `ERROR 08S01 (1043): Bad handshake'I am unable to write a bug report right now, so just dropping a quick warning here, before you upgrade your mysql server.
Jacob Coker-Dukowitz
08/19/2022, 11:14 PMprisma.$queryRaw`BEGIN`
prisma.$queryRaw`pg_advisory_xact_lock(5)`
// code, processing
prisma.$queryRaw`pg_advisory_xact_unlock(5)`
prisma.$queryRaw`COMMIT`
Yann Buydens
08/23/2022, 6:44 AMprisma.concept.findMany({
where: {
dictionaryId: Number(dictId),
name: {contains: foo}
},
include: {
_count: {
select: {
declarations: true, // including this in the query makes it super slow
},
},
}
})
I have a concept table and a declaration table. Concept and declaration have a many to many relationship. The declaration table has more than 500k rows, same goes for concept table.
longer explanation: https://www.loom.com/share/ff8d3034898e4ad08b8d19f044d500feFlorian Thelliez
08/24/2022, 11:36 AM$queryRaw()
Example query:
const rows = await this.prismaClient.$queryRaw<
{ id: string; location: string }[]
>(Prisma.sql`
SELECT id, ST_AsGeoJSON(location) as location,
FROM something
WHERE id IN (${Prisma.join(ids)})
`);
I get some type errors I didn’t have in previous versions:
ERROR: operator does not exist: uuid = text
I’ve tried various way to cast my list of ids
to uuids, but to no avail so far.
IN (${Prisma.join(ids)}::uuid[]) IN (${Prisma.join(ids)})::uuid[]
I wouldn’t mind some help there since I might be missing something simple 😅Trey Holterman
08/26/2022, 2:54 PMmodel Report {
id String @id @default(auto()) @map("_id") @db.ObjectId
...
team Team @relation(fields: [teamId], references: [id])
teamId String
...
}
Here’s the Team:
model Team {
id String @id @map("_id")
...
reports Report[]
...
}
I’ve tried creating a number of different ways. I thought the right way was as such:
const report = await prisma.report.create({
data: {
id : newId.toString(),
teamId: teamId,
...
},
});
Which gives error:
"Parse errors: [Query parsing/validation error at Mutation.createOneReport.data.ReportCreateInput.team: A value is required but not set"
Which I interpret to mean it’s missing the ‘team’ object.
So I tried:
const report = await prisma.report.create({
data: {
id : newId.toString(),
...
teamId: teamId,
team: {
connect: {
id: teamId,
},
},
...
},
});
Which errors out telling me I shouldn’t be including team Id. (will include error in thread). But if I don’t invlude teamId it errors out telling me I should be using teamId.
Very confusing since I used to be able to just add teamId in these types of situationsMartin Janeček
08/29/2022, 3:52 PMAustin
08/29/2022, 6:09 PMRich Starkie
08/30/2022, 2:08 PM//schema
model activityLog {
activityLogId String @id @map("_id") @default(uuid())
activityLogType activityLogType @relation(fields: [activityLogTypeId], references: [activityLogType])
activityLogTypeId String @db.ObjectId()
activityLogMessage String @db.String
activityCompleted Boolean @default(false)
createdAt DateTime @default(now()) @db.Timestamp
updatedAt DateTime @default(now()) @db.Timestamp
}
model activityLogType {
activityLogType String @id @map("_id") @db.String
createdAt DateTime @default(now()) @db.Timestamp
updatedAt DateTime @default(now()) @db.Timestamp
activityLog activityLog[]
}
when I try to do
await prisma.activityLog.create({
data: {
activityLogType: {
activityLogType: "Start"
},
activityLogMessage: "Start Seeding",
activityCompleted: true
}
})
The Start
document already exists in the activityLogTypes
collection
it complains that the activityLogType
does not exist schema
I'm probably doing something wrong, and its likely a n00b error for Mongo, but any help would be suggested.James Fox
08/30/2022, 5:31 PMCasey Chow
09/01/2022, 7:11 PMKay Khan
09/05/2022, 2:10 PM/core/prisma/schema.prisma
/lambda/prisma/schema.prisma
Core - This folder contains some core logic and is often "shared" code used by folder lambda
. Lambda folder is a serverless function more on that later.
core/prisma/schema.prisma
model Collection {
id String @id @default(auto()) @map("_id") @db.ObjectId
network String
contract_address String @unique
@@map("collections")
}
The convention for declaring a model here is familiar to the docs. https://www.prisma.io/docs/concepts/components/prisma-schema - Singular with a capital first letter.
core/models/collections.ts
Inside of this file im doing some common functionality like finding, inserting etc. Note: the model name that is being used "collection". Generated by the prisma library based on schema.prisma.
export const FindCollections = async () => {
try {
const contracts = await PrismaService.collection.findMany();
return [contracts, null] as const;
} catch (err) {
Logger.error({ kind: "FindCollections", error: err.name, stack_trace: err.stack });
return [null, err] as const;
}
};
Up until now, there are no problems.
Now lets introduce my lambda. I have this lambda folder which has my serverless function im going to deploy and i want to use "FindCollections" function within the core folder which has already been created.
However in my lambda folder, i need to introspect the database and package the engine. but when i introspect the database the model name becomes a problem.
lambda/prisma/prisma.schema
model collections {
id String @id @default(auto()) @map("_id") @db.ObjectId
contract_address String
...
}
You can now see its all lowercase with plural. Now with this introspected schema, my existing "FindCollections" function no longer works, because the model name is different.
InsertCollections","stack_trace":"Error: Could not find mapping for model Collection\nWhat is the suggestion for this usecase? There are 2 solutions i can think of but im wondering what you guys think.
Niv Oppenhaim
09/07/2022, 9:16 AM