kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
10.68k stars 271 forks source link

add `'bytea'` to column data types. #400

Closed loynoir closed 1 year ago

loynoir commented 1 year ago

https://www.postgresql.org/docs/current/datatype-binary.html

.addColumn("foobar", 'bytea')

Got type error Argument of type '"bytea"' is not assignable to parameter of type 'DataTypeExpression'


If use binary

.addColumn("foobar", 'binary')

got

> await up(db)
Uncaught:
error: type "binary" does not exist
    at Parser.parseErrorMessage (/path/to/node_modules/pg-protocol/dist/parser.js:287:98)
    at Parser.handlePacket (/path/to/node_modules/pg-protocol/dist/parser.js:126:29)
    at Parser.parse (/path/to/node_modules/pg-protocol/dist/parser.js:39:38)
    at Socket.<anonymous> (/path/to/node_modules/pg-protocol/dist/index.js:11:42)
    at Socket.emit (node:events:513:28)
    at Socket.emit (node:domain:552:15)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
    at PostgresConnection.executeQuery (file:///path/to/node_modules/kysely/dist/esm/dialect/postgres/postgres-driver.js:88:41)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///path/to/node_modules/kysely/dist/esm/query-executor/query-executor-base.js:35:28
    at async DefaultConnectionProvider.provideConnection (file:///path/to/node_modules/kysely/dist/esm/driver/default-connection-provider.js:10:20)
    at async DefaultQueryExecutor.executeQuery (file:///path/to/node_modules/kysely/dist/esm/query-executor/query-executor-base.js:34:16)
    at async CreateTableBuilder.execute (file:///path/to/node_modules/kysely/dist/esm/schema/create-table-builder.js:321:9)
    at Module.up (/path/to/reproduce.mts:20:3)
    at async REPL3:1:33
    at async node:repl:619:29 {
  length: 94,
  severity: 'ERROR',
  code: '42704',
  detail: undefined,
  hint: undefined,
  position: '121',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'parse_type.c',
  line: '270',
  routine: 'typenameType'
}

workaround

.addColumn("foobar", sql`bytea`)
koskimas commented 1 year ago

Your workaround is correct. binary is a datatype of another dialect.

loynoir commented 1 year ago

@koskimas

I think should add bytea to type, sqlbytea is ugly.

So, I open this issue, and link it with postgres doc

https://www.postgresql.org/docs/current/datatype-binary.html