小编J.D*_*.D.的帖子

续集时间戳名称

我有一个关于sequelize的小问题,我无法绕过它,这让我感到很生气.

我正在使用camelCase来获取我的所有模型属性,但我正在使用snake case将它们保存到数据库中(postgres).除非我想使用sequelize timestamps选项,否则该部分工作正常.

如果我设置underscored: false,时间戳将持久保存到camelCase中的数据库.

如果我设置underscored: true,它们会被持久化为snake_case但是它们在模型上是snake_case.

我想要实现的是数据库中的snake_case和用于模型时间戳的模型上的camelCase.

感觉这两个选项是互斥的.

谢谢

node.js sequelize.js

10
推荐指数
1
解决办法
2350
查看次数

MongoError:尝试写入外部缓冲区边界

我有一个简单的node.js代码,它试图获取对象,填充该字段,然后更新同一个对象:

var MongoClient = require('mongodb').MongoClient
, Db = require('mongodb').Db
, Server = require('mongodb').Server
, ObjectID = require('mongodb').ObjectID;

var db = new Db('testing', new Server('localhost', 27017));
db.open(function(err, db){
   var Users = db.collection('users');
   Users.find({code  : {$exists : false} }, {email : 1}, function(err,      users){
   users.forEach(function(user){
       var code = generateCode();
       var userID  = user._id;
       Users.update({ _id :  user._id  }, {$set : {code : code } }, function(err, results){
        if (err) console.log(err);
        else console.log(results);
       });

   });
});
Run Code Online (Sandbox Code Playgroud)

当我尝试更新mongo时抛出:

MongoError: attempt to write outside buffer …
Run Code Online (Sandbox Code Playgroud)

mongodb node.js mongodb-query

8
推荐指数
1
解决办法
2778
查看次数

Knex主键自动增量

我正在使用knex在postgres数据库中创建一个简单的表:

function up(knex, Promise) {
return knex.schema.createTableIfNotExists('communities', (table) => {

    table.increments('id').primary().unsigned();

    table.string('name', 255).notNullable();
    table.string('slug', 100).notNullable();

    table.timestamp('createdAt').defaultTo( knex.fn.now() );
    table.timestamp('updatedAt');
});
Run Code Online (Sandbox Code Playgroud)

};

function down(knex, Promise) {
  return knex.schema.dropTableIfExists(tableName);
};

module.exports = {
    tableName,
    up,
    down
}
Run Code Online (Sandbox Code Playgroud)

我的问题是table.increments('id').primary()创建一个默认值具有的主键,nextval('communities_id_seq'::regclass)我不能在没有id的情况下进行插入(即使在原始sql中).

有没有人知道如何默认增加id?

postgresql node.js knex.js

8
推荐指数
2
解决办法
7845
查看次数

如何在jQuery中创建Dictionary [Key:value]

我在html中有一个输入元素,它有两个重要的属性:id和parentElementId.

我想创建一个如下所示的地图/字典:"id:parentElementId".

var parent = $(".people-autocomplete").map( function(){ return $(this).attr('id')+':'+$(this).attr('parent'); }).get() ;
Run Code Online (Sandbox Code Playgroud)

因为我知道我将值放入一个字符串中,我稍后会在代码中解析它.我认为有一种比这更优雅的解决方案.

html javascript jquery dictionary

1
推荐指数
1
解决办法
2万
查看次数