Code Monkey home page Code Monkey logo

prisma-generator-drizzle's People

Contributors

daniel-nagy avatar farreldarian avatar scalahansolo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

prisma-generator-drizzle's Issues

Provide default export for all schema

Using schema.ts for drizzle-kit doesn't expose any schema.

export default defineConfig({
  schema: './drizzle/schema/schema.ts',
})

It can't find any tables from the schema.ts, but glob works fine

export default defineConfig({
  schema: './drizzle/schema/*',
})

Originally posted by @hilja in #18 (comment)

Option to suppress generator output?

First off, Im so thankful for this lib. Not yet using it in production, but it's allowing me to properly test Drizzle with my prod schemas and will make migrating off Prisma so much easier. Onto my idea...

My Prisma schema is pretty massive... I would love to have an option in the generator to suppress the output of the generator. I know where the files are going and it just ends up making a lot of noise and I run prisma generate

Check tsconfig and add .ts to imports

Screenshot 2024-01-12 at 17 16 01

Not a big problem, but if you’ve got something like this in tsonfig you need to import with .ts extension. Could also be a setting.

{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "target": "ES2022",
    "allowImportingTsExtensions": true,
  }
}

`prisma generate` throw Error: `Expected property name or '}' in JSON at position 29`

I followed the instructions in the README and executed the relevant commands.

However, when I reached the following command, an error occurred.

I searched extensively on search engines but couldn't find a solution.

image

generator client {
  provider = "prisma-generator-drizzle"
}

datasource db {
  provider = "sqlite"
  url      = "file:../prisma.db"
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
}
prisma:engines binaries to download libquery-engine, schema-engine +156ms
prisma:get-platform Found distro info:
{
  "targetDistro": "debian",
  "familyDistro": "debian",
  "originalDistro": "ubuntu"
} +4ms
prisma:get-platform Trying platform-specific paths for "debian" (and "ubuntu") +0ms
prisma:get-platform Found libssl.so file using platform-specific paths: libssl.so.3 +0ms
prisma:get-platform The parsed libssl version is: 3.0.x +0ms
prisma:loadEnv project root found at /home/work/package.json +246ms
prisma:tryLoadEnv Environment variables loaded from /home/work/.env +5ms
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
prisma:getConfig Using getConfig Wasm +3ms
prisma:getConfig config data retrieved without errors in getConfig Wasm +7ms
prisma:get-platform Found distro info:
{
  "targetDistro": "debian",
  "familyDistro": "debian",
  "originalDistro": "ubuntu"
} +1ms
prisma:get-platform Trying platform-specific paths for "debian" (and "ubuntu") +0ms
prisma:get-platform Found libssl.so file using platform-specific paths: libssl.so.3 +1ms
prisma:get-platform The parsed libssl version is: 3.0.x +0ms
prisma:getConfig Using getConfig Wasm +34ms
prisma:getConfig config data retrieved without errors in getConfig Wasm +1ms
prisma:getDMMF Using getDmmf Wasm +0ms
prisma:getDMMF Using given datamodel +0ms
prisma:getDMMF dmmf data retrieved without errors in getDmmf Wasm +36ms
prisma:getGenerators neededVersions {} +294ms
Error: Error: 
Expected property name or '}' in JSON at position 29


    at Mf.parse (/home/work/node_modules/.pnpm/[email protected]/node_modules/prisma/build/index.js:1413:71)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Rgt (/home/work/node_modules/.pnpm/[email protected]/node_modules/prisma/build/index.js:1892:280)

Respect default values in timestamps/dates

Given a simple Prisma model:

model Bar {
  foo       String
  createdAT DateTime @default(now())
}

It outputs something like:

import { pgTable, text, timestamp } from 'drizzle-orm/pg-core'

export const sites = pgTable('Bar', {
  foo: text('foo').notNull(),
  createdAT: timestamp('createdAT', { mode: 'date', precision: 3 }).notNull(),
})

Should it have a default value?

import { pgTable, text, timestamp } from 'drizzle-orm/pg-core'

export const sites = pgTable('Bar', {
  foo: text('foo').notNull(),
  createdAt: timestamp('createdAt', { mode: 'date', precision: 3 })
    .defaultNow()
    .notNull(),
})

Or default(sql`CURRENT_TIMESTAMP`). There seems to be some issues with it. Is it intentionally ambiguous?

v1

Planned Features

These are the essential features needed for querying and mutating purposes, providing 1:1 feature mapping from Prisma. Please mention if there's anything missed from this list.

Models

  • Field types
    • Scalar
      • Unsupported
    • List
    • Relations (e.g. []) for Drizzle relational query
    • Enum
  • Constraints
    • ID
    • primaryKey
    • notNull (when no ? modifier)
  • Custom @db. field

Helpers

Config

  • Support for all providers
    • postgres
    • mysql
    • sqlite

Not planned

v1 will concentrates exclusively on query and mutation operations, these parts are currently not on consideration:

Re-export all the models in the schema file

I am trying to create an internal package in my codebase that needs access to everything in my schema. Right now all the models are imported to build the schema, but I need access to those types outside of that one file and I don't want to have to seek into the individual files.

Maybe the generated directory should include an index.ts which exports out the schema as well as all the individual models?

Error: There is not enough information to infer relation...

I gotta say first I am beyond stoked on this library. My prisma schema is ~600 lines and the drizzle schema generation happened without error. However, I do get the following error when trying to load Drizzle Studio.

Error: There is not enough information to infer relation "__public__.catalogProducts.salesChannels"

CatalogProduct:

import {
  mysqlTable,
  text,
  datetime,
  boolean,
  int,
} from "drizzle-orm/mysql-core";
import { catalogProductTypeEnum } from "./catalog-product-type-enum";
import { catalogProductCategoryEnum } from "./catalog-product-category-enum";
import { relations } from "drizzle-orm";
import { variants } from "./variants";
import { externalProducts } from "./external-products";
import { salesChannels } from "./sales-channels";
import { externalUsers } from "./external-users";

export const catalogProducts = mysqlTable("CatalogProduct", {
  id: text("id").primaryKey(),
  createdAt: datetime("createdAt", { mode: "date", fsp: 3 }).notNull(),
  updatedAt: datetime("updatedAt", { mode: "date", fsp: 3 }).notNull(),
  title: text("title").notNull(),
  description: text("description"),
  productType: catalogProductTypeEnum("productType").notNull(),
  productCategory: catalogProductCategoryEnum("productCategory").notNull(),
  isActive: boolean("isActive").notNull(),
  retailPrice: int("retailPrice").notNull(),
  imageUrl: text("imageUrl"),
  isCustom: boolean("isCustom").notNull(),
  customExternalUserId: text("customExternalUserId"),
  customSkuIdentifier: text("customSkuIdentifier"),
  dielineTemplateUrl: text("dielineTemplateUrl"),
});

export const catalogProductsRelations = relations(
  catalogProducts,
  (helpers) => {
    return {
      variants: helpers.many(variants, {
        relationName: "CatalogProductToVariant",
      }),
      ExternalProduct: helpers.many(externalProducts, {
        relationName: "CatalogProductToExternalProduct",
      }),
      salesChannels: helpers.many(salesChannels, {
        relationName: "CatalogProductToSalesChannel",
      }),
      customExternalUser: helpers.one(externalUsers, {
        relationName: "CatalogProductToExternalUser",
        fields: [catalogProducts.customExternalUserId],
        references: [externalUsers.id],
      }),
    };
  },
);

SalesChannel Drizzle:

import { mysqlTable, text } from "drizzle-orm/mysql-core";
import { availableSalesChannelEnum } from "./available-sales-channel-enum";
import { relations } from "drizzle-orm";
import { catalogProducts } from "./catalog-products";

export const salesChannels = mysqlTable("SalesChannel", {
  id: text("id").primaryKey(),
  salesChannels: availableSalesChannelEnum("salesChannels").notNull(),
});

export const salesChannelsRelations = relations(salesChannels, (helpers) => {
  return {
    CatalogProduct: helpers.many(catalogProducts, {
      relationName: "CatalogProductToSalesChannel",
    }),
  };
});

Prisma:

model SalesChannel {
    id             String                @id @default(cuid())
    salesChannels  AvailableSalesChannel
    CatalogProduct CatalogProduct[]
}

model CatalogProduct {
    id                   String                 @id @default(cuid())
    createdAt            DateTime               @default(now())
    updatedAt            DateTime               @updatedAt
    title                String                 @db.Text
    description          String?                @db.Text
    productType          CatalogProductType
    productCategory      CatalogProductCategory
    isActive             Boolean                @default(false)
    retailPrice          Int
    imageUrl             String?
    variants             Variant[]
    ExternalProduct      ExternalProduct[]
    salesChannels        SalesChannel[]
    isCustom             Boolean                @default(false)
    customExternalUser   ExternalUser?          @relation(fields: [customExternalUserId], references: [id])
    customExternalUserId String?
    customSkuIdentifier  String?
    dielineTemplateUrl   String?

    @@index([customExternalUserId])
}

Cockroachdb provider support (same as postgres)

I saw that in your V1 notes, you didn't call out CockroachDB support. For the sake of this lib, I think it would just be simple enough to generate CockroachDB models in the same way you do Postgres. CockroachDB is designed and meant to be Postgres compatible.

datasource db {
  provider = "cockroachdb"
  url = env("DATABASE_URL")
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.