火灾的ORM

Gub*_*bbi 10 node.js google-cloud-firestore

在nodejs中是否有支持firestore的ORM?我特别习惯在python中喜欢ndb.

Sal*_*kar 11

我们正在研究一个(我们的意思是反应原生动物的反转酶/创造者).如果您之前在节点上使用过猫鼬或水线,那么您会发现它过于熟悉,因为我们正在使用它来获取灵感.

这一切仍然是内部的,但是为了让您了解api这里是我们内部的模型/用法示例之一:

const User = model('User', {
  // auto create/update date fields
  autoCreatedAt: true,
  autoUpdatedAt: true,

  // auto created/updated by fields, uses current auth user or 'service-account'
  autoUpdatedBy: true,
  autoCreatedBy: true,

  // toggle schema/less. If turned off, this will allow you to store arbitrary
  // data in a record. If turned on, only attributes defined in the model's
  // attributes object will be stored.
  schema: true,

  attributes: {
    first_name: {
      type: 'string',
      required: true
    },
    last_name: {
      type: 'string',
      required: true
    },

    // virtual field support
    full_name() {
      return `${this.first_name} ${this.last_name}`;
    },

    age: {
      type: 'integer'
    },
    email: {
      type: 'email',
      required: true
    },
    someBool: {
      type: 'boolean',
      defaultsTo: false
    },

    // association example- in this case a child collection of the users doc
    // e.g /users/id/posts
    posts: {
      collection: 'posts',
    }
  }
});

// magic methods based on attributes
// findByX or findOneByX
User.findByAge(27).then((val) => {
  // val = [] or [document object]
}).catch((error) => {
  debugger;
});

// magic methods based on attributes
// findByX or findOneByX
User.findByName('mike').then((val) => {
  // val = [] or [document object]
}).catch((error) => {
  debugger;
});

// find a single document
User.findOne().then((val) => {
  // val = undefined or document object
}).catch((error) => {
  debugger;
});

// find multiple docs
User.find({
  name: 'mike',
  age: 27,
  someBool: true,
}).then((val) => {
  // val = [] or [document object]
}).catch((error) => {
  debugger;
});

// find multiple docs with age between range
User.find({
  someBool: true,
  age: {
    $gte: 27,
    $lte: 35
  }
}).then((val) => {
  // val = [] or [document object]
}).catch((error) => {
  debugger;
});
Run Code Online (Sandbox Code Playgroud)

留意我们的不和谐,Github组织或推特 - 希望在几天内有一个公共alpha版.

上面的示例没有展示我们正在计划的所有内容,但我们计划支持诸如分页(跳过,限制,页面),createOrUpdate,findOrCreate,subscribe()之类的东西 - 用于实时,多范围过滤器(第一个发送到firestore) ,其余完成客户端)等

更新:

很早就回购已经在github公开.它通常有效,文档仍然需要做和一些事情缺少代码明智 - 用于查看测试 - 它经过充分测试(测试驱动开发),如果你想贡献那么请做:)我们暂停Firepit现在,我们正在推动React Native Firebase的发布.

  • 这个项目怎么了? (2认同)