2017-10-12 23 views
1

有沒有任何ORM支持nodejs中的firestore?我特別喜歡Python中的ndb。ORM for firestore

+1

到目前爲止我還沒有意識到(而且我們還沒有創建任何)。 –

回答

5

我們正在研究一個(我們的意思是Invertase/creators of react-native-firebase)。如果您之前在節點上使用過貓鼬或水線,那麼您會發現它過於熟悉,因爲這正是我們用來獲取靈感的地方。

這一切還是內部的,而是給你的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; 
 
});

隨時留意我們的不和諧,Github org或twitter - 希望在幾天內擁有公共的alpha。

上面的例子並不展示我們計劃的一切,但我們計劃支持之類的東西paginations(跳躍,限制,頁),createOrUpdate,findOrCreate,訂閱() - 用於實時,多範圍過濾器(第一一個發送到公司的FireStore,剩下的做客戶端)等

更新:

在github here一對回購很早就已經公開。它通常有效,文檔仍然需要做,缺少代碼明智的一些東西 - 使用看到測試 - 它已經很好地測試(測試驅動開發),如果你想貢獻,然後請做:)我們暫停爲Firepit目前我們正在推出React Native Firebase版本。

+1

這是怎麼回事? – sirvon

+0

@sirvon描述更新了更多信息+回購鏈接 – Salakar