L-Mario564 / drizzle-dbml-generator

Generate DBML markup from your schema defined with Drizzle ORM.
MIT License
161 stars 8 forks source link

Can't get generate function to work with any combination of syntax/tools #6

Closed kevinschaich closed 11 months ago

kevinschaich commented 11 months ago

If I run:

node --experimental-specifier-resolution=node --loader ts-node/esm ./db/generate-dbml.mts

with ES6 syntax, I get:

(node:452) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

If I run:

npx tsx ./db/generate-dbml.ts

with ES6 syntax, I get:

/Users/kevinschaich/repositories/arlo-quoting-tool/node_modules/drizzle-dbml-generator/dist/index.cjs:139
    const dbml = new DBML().tab().escapeSpaces(column.name).insert(" ").escapeType(column.getSQLType());
TypeError: column.getSQLType is not a function

If I run:

node --experimental-specifier-resolution=node --loader ts-node/esm ./db/generate-dbml.mts

with node require syntax, I get:

(node:99972) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

If I run:

npx tsx ./db/generate-dbml.ts

with node require syntax, I get:

/Users/kevinschaich/repositories/arlo-quoting-tool/node_modules/drizzle-dbml-generator/dist/index.cjs:139
    const dbml = new DBML().tab().escapeSpaces(column.name).insert(" ").escapeType(column.getSQLType());

TypeError: column.getSQLType is not a function

require syntax code:

const schema = require('./schema')
const drizzleDbmlGenerator = require('drizzle-dbml-generator')

drizzleDbmlGenerator.pgGenerate({ schema, out: './db/schema.dbml', relational: true })

ES6 syntax code:

import * as schema from './schema'
import { pgGenerate } from 'drizzle-dbml-generator' // Using Postgres for this example

pgGenerate({ schema, out: './db/schema.dbml', relational: true })

5 seems relevant for the TypeError: column.getSQLType is not a function piece.

L-Mario564 commented 11 months ago

Are you also using Drizzle ORM v0.29.0? And are you using any custom columns like the one described in #5?

kevinschaich commented 11 months ago

Yes, drizzle-orm v0.29.0.

Not sure what qualifies as a custom column, everything I'm importing is from drizzle-orm/pg-core. There's no custom JSON or anything.

import { boolean, date, doublePrecision, pgEnum, pgTable, text, uuid } from 'drizzle-orm/pg-core'
import { v4 as uuid_v4 } from 'uuid'
L-Mario564 commented 11 months ago

Ah I see. Something must have changed in the latest release then. I'll take a look and hopefully patch this soon.

iLegacy commented 11 months ago

@L-Mario564 can you publish so we’d be able to install this fix?