How to use the @google-cloud/firestore.Transaction function in @google-cloud/firestore

To help you get started, we’ve selected a few @google-cloud/firestore 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 1amageek / pring-admin.ts / lib / base.js View on Github external
async fetch(transaction) {
        try {
            let snapshot;
            if (transaction) {
                if (transaction instanceof firebase.firestore.Transaction) {
                    snapshot = await transaction.get(this.reference);
                }
                if (transaction instanceof FirebaseFirestore.Transaction) {
                    snapshot = await transaction.get(this.reference);
                }
            }
            else {
                snapshot = await this.reference.get();
            }
            const data = snapshot.data();
            if (data) {
                this.setData(data);
                this.isSaved = true;
            }
        }
        catch (error) {
            throw error;
        }
    }
github 1amageek / pring-admin.ts / lib / subCollection.js View on Github external
async get(type, transaction) {
        try {
            let snapshot;
            if (transaction instanceof FirebaseFirestore.Transaction) {
                const reference = this.reference;
                snapshot = await transaction.get(reference);
            }
            else {
                snapshot = await this.reference.get();
            }
            const docs = snapshot.docs;
            const documents = docs.map((documentSnapshot) => {
                const document = new type(documentSnapshot.id, {});
                document.setData(documentSnapshot.data());
                return document;
            });
            this.objects = documents;
            return documents;
        }
        catch (error) {