Hi friends, i wanted to ask about naming conventio...
# prisma-client
k
Hi friends, i wanted to ask about naming convention of models and how it relates to reusing code and pulling/introspection. Let me explain the scenario. Folder structure
Copy code
/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
Copy code
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.
Copy code
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
Copy code
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\n
What is the suggestion for this usecase? There are 2 solutions i can think of but im wondering what you guys think.
✅ 1
h
You can manually add
@map
to lambda schema and prisma will preserve it with further re-introspections. https://www.prisma.io/docs/concepts/components/introspection?query=json&page=1#introspection-with-an-existing-schema