denodb icon indicating copy to clipboard operation
denodb copied to clipboard

Issue when trying to save json

Open futbotism opened this issue 5 years ago • 2 comments

When I try to save json in the database I seem to get the error below, I am using postgres

export class ReflectionEntity extends Model {
  static table = "reflections";

  static fields: Record<keyof Reflection, FieldType> = {
    id: {
      primaryKey: true,
      type: DataTypes.INTEGER,
      autoIncrement: true,
    },
    notes: {
      type: DataTypes.JSON,
    }
  };
}
api_1       | ReferenceError: Buffer is not defined
api_1       |     at escapeFn (https://raw.githubusercontent.com/denjucks/dex/master/lib/query/string.js:44:16)
api_1       |     at finalEscape (https://raw.githubusercontent.com/denjucks/dex/master/lib/query/string.js:18:12)
api_1       |     at arrayString (https://raw.githubusercontent.com/denjucks/dex/master/lib/dialects/postgres/index.js:315:64)
api_1       |     at escapeArray (https://raw.githubusercontent.com/denjucks/dex/master/lib/dialects/postgres/index.js:56:18)
api_1       |     at escapeFn (https://raw.githubusercontent.com/denjucks/dex/master/lib/query/string.js:43:18)
api_1       |     at Client_PG.finalEscape [as _escapeBinding] (https://raw.githubusercontent.com/denjucks/dex/master/lib/query/string.js:18:12)
api_1       |     at https://raw.githubusercontent.com/denjucks/dex/master/lib/client.js:151:19
api_1       |     at String.replace (<anonymous>)
api_1       |     at Client_PG._formatQuery (https://raw.githubusercontent.com/denjucks/dex/master/lib/client.js:143:16)
api_1       |     at https://raw.githubusercontent.com/denjucks/dex/master/lib/interface.js:13:28

futbotism avatar Nov 26 '20 20:11 futbotism

Hi! If you still get this error, you have to parse the JSON to a string with JSON.stringify function. Tell me if that works!

jrdx0 avatar Nov 29 '20 02:11 jrdx0

This is still an issue but for a different reason. It is impossible to update entries containing a JSON field because getting the entry parses the JSON, and if the JSON field isn't updated it will still be parsed JSON when doing entry.update(), throwing an error because it's supposed to be stringified before saving.

JSEverything avatar Feb 23 '21 17:02 JSEverything