Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.
/ nestjs-firestore Public archive

A NestJS Module for the Firestore Google Cloud SDK

License

Notifications You must be signed in to change notification settings

gelouko/nestjs-firestore

Repository files navigation

All Contributors Known Vulnerabilities

NestJS Firestore

Firestore module for Nest.

This project is active, but under construction. Check the repository v1.0 project to see what's coming next.

If there's something you'd love to have here, feel free to create an issue. We'll do our best to answer in 2 days!

Installation

In your Nest generated project, run

$ npm i --save nestjs-firestore @google-cloud/firestore

Usage

Check the test/e2e/src code for a full working example

// Root module
@Module({
    imports: [FirestoreModule.forRoot()],
})
export class RootModule {}

// Module which you want to use a repository:
@Module({
    imports: [FirestoreModule.forFeature([Cat])],
    controllers: [CatsController],
    providers: [CatsService],
})
export class CatsModule {}

// The service where you will inject the repository
@Injectable()
export class CatsService {
    constructor(
        @InjectRepository(Cat)
        private readonly catRepository: FirestoreRepository<Cat>,
    ) {
    }

    async create(cat: Cat): Promise<Cat> {
        return await this.catRepository.create(cat);
    }

    async findById(id: string): Promise<Cat | null> {
        return this.catRepository.findById(id);
    }
}

Using the firestore client

We understand that sometimes there might be a feature in the cli that we haven't implemented yet

In this case, you can directly inject the Firestore class, and it will use the configured instance in forRoot

@Injectable()
export class CatsService {
    constructor(
        private readonly firestoreCli: Firestore,
    ) {}
    
    async update(cat: Cat): Promise<Cat> {
        // update some fields of a document without overwriting the entire document, use the following language-specific update() method:
        await this.firestoreCli.collection(cats).doc(cat.id).update({ name: 'Frank' });
    }
}

Contribute

Check the .github/contributing.md file to learn how to contribute including steps to build the project and the guidelines for contributing

Contributors

maddy020
maddy020

📖
Giulio Denardi
Giulio Denardi

💻 📖 🤔 🚧 📆 ⚠️

License

nestjs-firestore is MIT licensed.

About

A NestJS Module for the Firestore Google Cloud SDK

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published