Matusko167
Matusko167
PPrisma
Created by Matusko167 on 6/7/2024 in #help-and-questions
make from model.prisma sql
ouu 😦 and its possible it will be implements in short time or i need to find another way? 🙂
15 replies
PPrisma
Created by Matusko167 on 6/7/2024 in #help-and-questions
make from model.prisma sql
i want just send user.prisma file to some fucntion with provider and get back sql statement, or some function to send 2 files where these 2 files will be checked and return me differences in sql alter code
15 replies
PPrisma
Created by Matusko167 on 6/7/2024 in #help-and-questions
make from model.prisma sql
becouse i cant find any functon inside prisma which can help me
15 replies
PPrisma
Created by Matusko167 on 6/7/2024 in #help-and-questions
make from model.prisma sql
i make this code but its not good becouse i cant handle relations and many things
15 replies
PPrisma
Created by Matusko167 on 6/7/2024 in #help-and-questions
make from model.prisma sql
import { getDMMF } from "@prisma/sdk"; import fs from "fs"; import path from "path"; async function generateSQL() { // Read your Prisma schema file const schemaPath = path.join(dirname, "schema.prisma"); const schema = fs.readFileSync(schemaPath, "utf-8"); // Get the DMMF (Data Model Meta Format) from the schema const dmmf = await getDMMF({ datamodel: schema }); // Initialize SQL string let sql = ""; // Iterate over the models and generate SQL statements for (const model of dmmf.datamodel.models) { sql += CREATE TABLE ${model.name} (\n; for (const field of model.fields) { sql += ${field.name} ${getSqlType(field)}${ field.isRequired ? " NOT NULL" : "" },\n; } // Remove the trailing comma and newline sql = sql.slice(0, -2); // Add primary key constraint const idFields = model.fields.filter((field) => field.isId); if (idFields.length) { sql += ,\n PRIMARY KEY (${idFields .map((field) => field.name) .join(", ")}); } sql += \n);\n\n; } // Write the generated SQL to a file fs.writeFileSync(path.join(dirname, "generated.sql"), sql); console.log("SQL generated successfully!"); } function getSqlType(field: any): string { switch (field.type) { case "String": return "VARCHAR(255)"; case "Int": return "INTEGER"; case "BigInt": return "BIGINT"; case "Float": return "FLOAT"; case "Decimal": return "DECIMAL"; case "Boolean": return "BOOLEAN"; case "DateTime": return "TIMESTAMP"; case "Json": return "JSON"; case "Bytes": return "BYTEA"; default: if (field.kind === "object") { return "INTEGER"; // Foreign key reference, typically an integer } return "TEXT"; } } generateSQL().catch((e) => console.error(e));
15 replies
PPrisma
Created by Matusko167 on 6/7/2024 in #help-and-questions
make from model.prisma sql
i am trying with chatgpt and geminy to create some parser but wihtout any solution
15 replies
PPrisma
Created by Matusko167 on 6/7/2024 in #help-and-questions
make from model.prisma sql
what i found inside documentation nothing helps me 😦
15 replies
PPrisma
Created by Matusko167 on 6/7/2024 in #help-and-questions
make from model.prisma sql
where is not defined datasource and generator?
15 replies
PPrisma
Created by Matusko167 on 6/7/2024 in #help-and-questions
make from model.prisma sql
but can i call it only for one file like user.prisma?
15 replies
PPrisma
Created by Matusko167 on 6/7/2024 in #help-and-questions
make from model.prisma sql
No description
15 replies
PPrisma
Created by Matusko167 on 5/22/2024 in #help-and-questions
Prisma custom flow
Yea sure so we want to have custom cycle of that what happend inside commands like prisma generate or prisma db push or prisma db migrate, not full custom but we want to call it inside our code. It is possible to do something like that?
5 replies