Tag: 模式

PostgreSQL的Sequelize模式:如何在模型中准确定义模式?

我search了整个networking,并没有能够确定如何添加一个模式到这个下面的续集模型。 下面的代码不会反弹错误,但是当我检查postgres数据库时,唯一的模式是公共的默认模式。 // The model definition is done in /path/to/models/project.js module.exports = function(sequelize, DataTypes) { return sequelize.define("project", { name: DataTypes.STRING, description: DataTypes.TEXT, }, define: { schema: "prefix" }, classMethods: { method1: function() {}, method2: function() {} }, instanceMethods: { method3: function() {} }) 应如何修改脚本以准确定义模式? 编辑 就我而言,最终的答案是 database_name.sequelize.createSchema('prefix').then(() => {…}); 在我的./models/index.js文件中,数据库对象如下所示: database_name = { Sequelize: Sequelize, […]

将模型添加到从Mongoose模式派生的模型中

我有一个Mongoose模式,看起来像这样: ManifestSchema = new Schema({ entries: [{ order_id: String, line_item: {}, // <– resolved at run time address: {},// <– resolved at run time added_at: Number, stop: Number, }] }, {collection: 'manifests', strict: true }); 并在代码中的某处我有这样的: Q.ninvoke(Manifests.findById(req.params.id), 'exec') .then(function(manifest) { // … so many things, like resolving the address and the item information entry.line_item = […]

foo.find(…).execFind不是函数 – mongoose模式模型

我已经定义了一个自定义的types,我试图从被引用的集合中包含的mongo返回所有的条目: Participant.js var mongoose = require('mongoose'); var Schema = mongoose.Schema; var participantSchema= new Schema({ email: String, }); module.exports = mongoose.model('Participant', participantSchema, 'participants') api.js var express = require('express'); var router = express.Router(); var mongoose = require('mongoose'); var Participant = require('../models/Participant'); router.get('/all', function(req, res) { var participant = mongoose.model('Participant'); //var participant = new Participant(); console.log(participant); participant.find().execFind(function (arr,data) […]

如何将JSON模式转换为mongoose模式

有没有办法像下面那样采用有效的JSON模式,并把它变成mongoose模式? { "$schema": "http://json-schema.org/draft-04/schema#", "description": "some desc", "title": "Product", "type": "object", "properties": { "endpoints": { "type": "array", "items": { "type": "string" } }, "poi": { "type": "array", "items": { "type": "object", "properties": { "location_name": { "type": "string" }, "distance": { "type": "string" } } } } } } 这对我来说似乎是如此基本和简单,但我还没有在网上find任何东西。 有很多关于如何获取JSON模式的例子,并且有大量的例子来说明如何从这样的对象中创buildmongoose模式: const newSchema = new mongoose.Schema({ […]

mongoose里的2个混合对象的Schema数组

嘿我试图做一个数组到一个数组,它们都是混合types,多数民众赞成我是如何build立它 var Fields = new Schema({ type: {type: String}, length: {type: Number}, lable: {type: String}, name: {type: String} }); var Fieldsets = new Schema({ label: {type: String}, name: {type: String}, fields: {type: [Fields]} }); var Steps = new Schema({ order: {type: Number}, name: {type: String}, fieldsets: {type: [Fieldsets]} }); var FormSchema = new Schema({ name: […]

如何在nodejs中为neo4jgraphics数据库创build模式?

我在想,我们如何防止用户/开发人员添加不需要的节点/关系/属性? 我读的是 – 我们应该在应用程序层面强加这些模式。 那么,我们如何在Node.js中做到这一点? 有没有这样的例子? 或者有人可以在这里发布一些代码?

在Mongoose中,如何声明dynamicSchema

我是Mongoose的新手,在官方文档中我没有发现任何与我需要的东西有关的东西。 我怎样才能声明一个dynamic的子模式? 例如: var A = new Schema({ name : String, subtype : String, description : String }); var B = new Schema({ name : String, description : String }); var C = new Schema({ name : String, type : [if(type.value == 'A') then uses Schema-A; if(type.value == 'B') then uses Schema-B; ] }); 希望这是有道理的。 […]

如何在OS X上使用node.js检测隐藏的文件

在我周围徘徊无法发现一种方法来检测OS X中与节点(nodejs)的隐藏文件。 当然,我们可以很容易地find“.dot_hidden”文件,但是在Mac上,有一些文件/文件夹是“受保护的”系统文件,大多数用户不应该摆弄。 在Finder GUI中,当隐藏文件被迫通过“AppleShowAllFiles”显示时,它们是不可见的或灰色的。 我确实发现了对UF_HIDDEN的引用:0x8000在这里: https://developer.apple.com/library/mac/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemDetails/FileSystemDetails.html 使用节点的统计信息,我们可以返回2个额外的信息,可以提供隐藏状态的线索: mode: 33188, // File protection. ino: 48064969, // File inode number. An inode is a file system data structure that stores information about a file. 我不是一个hex/二进制的人,但它看起来像抓住统计的“ino”属性,我们可以申请0x8000,并确定该文件被暗示为隐藏或不。 我没有在模式上的0x8000掩码成功,但确实有一些ino。 这是我得到的,检查“ino”返回0或1726年,当它是1726该文件似乎匹配OS X中的隐藏文件。 var fs = require("fs"); var dir = "/"; var list = fs.readdirSync(dir); list.forEach(function(f){ // easy dot hidden files […]

mongoose纲要与Mongovalidation器

Mongo 3.2有文档validation,我们可以使用相同的定义一个模式,而不是使用mongoose这样做。 例如 : mongoose userschema = mongoose.Schema({ org: String, username: String, fullname: String, password: String, email: String }); MongoDB的 db.createCollection( "example",{ validator:{ $and:[ { "org":{$type:"string"}}, { "username":{$type:"string"}}, { "fullname":{$type:"double"}}, {"password":$type:"string"}}, {"email":{$type:"string"}} ] }, validationLevel:"strict", validationAction:"error" }) 这些拖曳之间的区别是什么,我们可以提供一个可选的字段使用validation程序在架构?

如何发布和更新模式数组中的模式并打印它?

你好,我是新的节点js和mongoose我有两个计划,我想在其他架构模式对象我的计划 user.js的 // grab the things we need var mongoose = require('mongoose'); var Schema = mongoose.Schema; var Genre = require('../Models/genre'); // create a schema var userSchema = new Schema({ name: { type: String, required: true, unique: true , index:true}, email: { type: String, required: true, unique: true }, password: { type: String, required: true }, […]