How to use the warehouse.Schema function in warehouse

To help you get started, we’ve selected a few warehouse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hexojs / hexo / lib / models / cache.js View on Github external
module.exports = ctx => {
  const Cache = new Schema({
    _id: {type: String, required: true},
    hash: {type: String, default: ''},
    modified: {type: Number, default: Date.now() } // UnixTime
  });

  Cache.static('compareFile', function(id, hashFn, statFn) {
    const cache = this.findById(id);

    // If cache does not exist, then it must be a new file. We have to get both
    // file hash and stats.
    if (!cache) {
      return Promise.all([hashFn(id), statFn(id)]).spread((hash, stats) => this.insert({
        _id: id,
        hash,
        modified: stats.mtime.getTime()
      })).thenReturn({
github hexojs / hexo / lib / models / post_asset.js View on Github external
module.exports = ctx => {
  const PostAsset = new Schema({
    _id: {type: String, required: true},
    slug: {type: String, required: true},
    modified: {type: Boolean, default: true},
    post: {type: Schema.Types.CUID, ref: 'Post'},
    renderable: {type: Boolean, default: true}
  });

  PostAsset.virtual('path').get(function() {
    const Post = ctx.model('Post');
    const post = Post.findById(this.post);
    if (!post) return;

    // PostAsset.path is file path relative to `public_dir`
    // no need to urlescape, #1562
    // strip /\.html?$/ extensions on permalink, #2134
    return pathFn.join(_.replace(post.path, /\.html?$/, ''), this.slug);
github hexojs / hexo / lib / models / page.js View on Github external
module.exports = ctx => {
  const Page = new Schema({
    title: {type: String, default: ''},
    date: {
      type: Moment,
      default: moment,
      language: ctx.config.languages,
      timezone: ctx.config.timezone
    },
    updated: {
      type: Moment,
      default: moment,
      language: ctx.config.languages,
      timezone: ctx.config.timezone
    },
    comments: {type: Boolean, default: true},
    layout: {type: String, default: 'page'},
    _content: {type: String, default: ''},
github hexojs / hexo / lib / models / post_category.js View on Github external
module.exports = ctx => {
  const PostCategory = new Schema({
    post_id: {type: Schema.Types.CUID, ref: 'Post'},
    category_id: {type: Schema.Types.CUID, ref: 'Category'}
  });

  return PostCategory;
};
github hexojs / hexo / lib / model / schema.js View on Github external
escape = util.escape;

var Schema = require('warehouse').Schema,
  Moment = require('./types/moment');

var isEndWith = function(str, last){
  return str[str.length - 1] === last;
};

var permalinkGetter = function(){
  var url = hexo.config.url;

  return url + (isEndWith(url, '/') ? '' : '/') + this.path;
};

var Post = exports.Post = new Schema({
  id: Number,
  title: {type: String, default: ''},
  date: {type: Moment, default: moment},
  updated: {type: Moment, default: moment},
  categories: [{type: String, ref: 'Category'}],
  tags: [{type: String, ref: 'Tag'}],
  comments: {type: Boolean, default: true},
  layout: {type: String, default: 'post'},
  content: {type: String, default: ''},
  excerpt: {type: String, default: ''},
  more: {type: String, default: ''},
  source: {type: String, required: true},
  slug: {type: String, required: true},
  photos: [String],
  link: {type: String, default: ''},
  raw: {type: String, default: ''}
github hexojs / hexo / lib / model / schema.js View on Github external
return hexo.extend.filter.apply('post_permalink', this);
});

Post.virtual('permalink', permalinkGetter);

Post.virtual('full_source', function(){
  return path.join(hexo.source_dir, this.source);
});

Post.virtual('asset_dir', function(){
  var src = this.full_source;

  return src.substring(0, src.length - path.extname(src).length) + path.sep;
});

var Page = exports.Page = new Schema({
  title: {type: String, default: ''},
  date: {type: Moment, default: moment},
  updated: {type: Moment, default: moment},
  comments: {type: Boolean, default: true},
  layout: {type: String, default: 'page'},
  content: {type: String, default: ''},
  excerpt: {type: String, default: ''},
  source: {type: String, required: true},
  path: {type: String, required: true},
  raw: {type: String, default: ''}
});

Page.virtual('permalink', permalinkGetter);

Page.virtual('full_source', function(){
  return path.join(hexo.source_dir, this.source);
github hexojs / hexo / lib / model / schema.js View on Github external
return str;
});

Category.virtual('path', function(){
  var catDir = hexo.config.category_dir;

  return catDir + (isEndWith(catDir, '/') ? '' : '/') + this.slug + '/';
});

Category.virtual('permalink', permalinkGetter);

Category.virtual('length', function(){
  return this.posts.length;
});

var Tag = exports.Tag = new Schema({
  name: {type: String, required: true},
  posts: [{type: String, ref: 'Post'}]
});

Tag.virtual('slug', function(){
  var map = hexo.config.tag_map,
    name = this.name;

  name = map && map.hasOwnProperty(name) ? map[name] : name;
  return escape.filename(name, hexo.config.filename_case);
});

Tag.virtual('path', function(){
  var tagDir = hexo.config.tag_dir;

  return tagDir + (isEndWith(tagDir, '/') ? '' : '/') + this.slug + '/';
github hexojs / hexo / lib / model / schema.js View on Github external
return tagDir + (isEndWith(tagDir, '/') ? '' : '/') + this.slug + '/';
});

Tag.virtual('permalink', permalinkGetter);

Tag.virtual('length', function(){
  return this.posts.length;
});

var Cache = exports.Cache = new Schema({
  _id: {type: String},
  mtime: {type: Number, default: Date.now}
});

var Asset = exports.Asset = new Schema({
  _id: {type: String},
  path: {type: String},
  modified: {type: Boolean, default: true},
  post_id: {type: String, ref: 'Post'},
  post_path: {type: String}
});
github hexojs / hexo / lib / models / data.js View on Github external
module.exports = ctx => {
  const Data = new Schema({
    _id: {type: String, required: true},
    data: Object
  });

  return Data;
};
github hexojs / hexo / lib / models / post_tag.js View on Github external
module.exports = ctx => {
  const PostTag = new Schema({
    post_id: {type: Schema.Types.CUID, ref: 'Post'},
    tag_id: {type: Schema.Types.CUID, ref: 'Tag'}
  });

  return PostTag;
};