-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
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?