{
"id": "_9y0eqwalx",
"tags": [
"test",
"python",
"sheets"
],
"title": "Whats your plans?",
"textBody": " Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
"__v": 1,
"time": "2018-08-23T20:24:45.294Z",
"length": 2306,
"index": 4
},
所以我需要每个笔记的数据看起来像这样。问题带有“标签”,它不允许我发布数组。我尝试执行以下操作。
exports.up = function(knex, Promise) {
return knex.schema.createTable('notes', function(tbl){
tbl.string("id").notNullable()
tbl.string('title').notNullable()
tbl.string('textBody').notNullable()
tbl.integer('__v').defaultTo(0)
tbl.integer("length")
tbl.string("time")
tbl.enu('tags',[]).notNullable()
})
};
但是,“标签”列始终为空。如何设置knex表以接受数组?
答案 0 :(得分:0)
要给出更好的答案,我实际上需要知道您使用的是哪个数据库引擎。
除了将其存储为序列化字符串之外,没有其他任何数据库不可知的方式来存储数组。几个简单的序列化选择是JSON.stringify()
和JSON.parse()
或string.split(',')
和string.join(',')
。无论如何,每次您写入/读取这些枚举数组都需要手动转换。
要在knex中创建真实的数组列,您需要使用.specificType()
并将原始列类型提供给数据库。或者,您可以在Postgresql上使用.jsonb()
类型,并将数据存储为json数组。
Knex对使用json类型的支持不多,因此在knex之上使用Objection.js可能会更好(它支持许多postgresql json操作)。