Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import db from '../db';
- /*
- Options:
- - ref: Specify the ref of a document
- - collectionName: Specify the collection name
- - queryArgs: Specify the arguments to be passed down to .where()
- - orderByArgs: Specify the arguments to be passed down to .orderBy()
- - limit: Specify the fetching limit
- - docName: Specify the document name/id
- */
- export default options => {
- const { ref, collectionName, queryArgs, orderByArgs, limit, docName } = options;
- if (ref != null) return ref;
- const initRef = db.collection(collectionName);
- if (docName != null) return initRef.doc(docName);
- if (queryArgs != null) {
- if (orderByArgs != null) {
- if (limit != null)
- return initRef
- .where(...queryArgs)
- .orderBy(...orderByArgs)
- .limit(limit);
- return initRef.where(...queryArgs).orderBy(...orderByArgs);
- }
- return initRef.where(...queryArgs);
- }
- return initRef;
- };
Add Comment
Please, Sign In to add comment