Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column options default value not be Object #115

Closed
mingyang91 opened this issue Dec 9, 2016 · 4 comments
Closed

Column options default value not be Object #115

mingyang91 opened this issue Dec 9, 2016 · 4 comments

Comments

@mingyang91
Copy link
Contributor

Code:

  @Column('json', { default: {} })
  @Type(type => Result)
  @Reflect.metadata('design:type', Result)
  public result: Result = {}

Error Query:

CREATE TABLE "candidate" ("phone" character varying(255), "industry" character varying(255), "years" integer, "degree" integer, "resume" json NOT NULL DEFAULT '[object Object]', "status" integer NOT NULL, "id" SERIAL NOT NULL PRIMARY KEY, "createAt" timestamp without time zone NOT NULL, "updateAt" timestamp without time zone NOT NULL, "version" integer NOT NULL, "location" integer, "creator" integer, "company" integer)

Error:

{ error: invalid input syntax for type json
    at Connection.parseE (/var/app/current/node_modules/pg/lib/connection.js:554:11)
    at Connection.parseMessage (/var/app/current/node_modules/pg/lib/connection.js:381:17)
    at Socket.<anonymous> (/var/app/current/node_modules/pg/lib/connection.js:117:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:172:18)
    at Socket.Readable.push (_stream_readable.js:130:10)
    at TCP.onread (net.js:542:20)
  name: 'error',
  length: 157,
  severity: 'ERROR',
  code: '22P02',
  detail: 'Token "object" is invalid.',
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: 'JSON data, line 1: [object...',
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'json.c',
  line: '1243',
  routine: 'report_invalid_token' }

Should the type of this field be constrained?

    /**
     * Default database value.
     */
    readonly default?: any;
@pleerock
Copy link
Member

pleerock commented Dec 9, 2016

Try to set: default: "{}" instead

@pleerock
Copy link
Member

any success with this issue?

@mingyang91
Copy link
Contributor Author

This workaround is feasible.

Can you constrain default to a normal value type?
Or just to provide a description, default can not be object?

@pleerock
Copy link
Member

Its not a workaround, its actual implementation. Default's value is just used in DEFAULT expression of sql. Right now its {} if you want to store an object there, later I have plans to change it to '{}' because of #150 . I think I can close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants