Thanks to visit codestin.com
Credit goes to github.com

Skip to content

JSON on unsupported dbs #300

@Page-

Description

@Page-

I'm using knex 0.6.2 with sqlite3, I have a column defined as json (unsupported I know) and am trying to figure out how to insert/select this data, this is my test case:

var knex = require('knex').initialize({
  client: 'sqlite3',
  connection: {
    filename: 'db.sqlite'
  }
});
knex.schema.createTable('test', function(t) {
  t.increments('id').primary()
  t.json('json')
}).then(function() {
  knex('test').insert({
    json: {
      a: 'b'
    }
  })
}).then(function() {
  knex('test').insert({
    json: JSON.stringify({
      a: 'b'
    })
  })
}).then(function() {
  knex('test').select()
}).then(function(data) {
  console.log(data) // [ { id: 1, json: null }, { id: 2, json: '{"a":"b"}' } ]
})

Should I just be treating it (and/or defining?) as a text field and making sure to manually JSON.stringify before insert/update, and JSON.parse on select? Or I am missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions