GithubHelp home page GithubHelp logo

gelouko / nestjs-firestore Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 1.27 MB

A NestJS Module for the Firestore Google Cloud SDK

License: MIT License

JavaScript 1.70% Shell 0.34% TypeScript 97.96%

nestjs-firestore's Introduction

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.

nestjs-firestore's People

Contributors

gelouko avatar dependabot[bot] avatar allcontributors[bot] avatar maddy020 avatar snyk-bot avatar

Stargazers

 avatar Bima Putra Lamanda avatar Lucas Coelho avatar

Watchers

 avatar Kostas Georgiou avatar

Forkers

maddy020

nestjs-firestore's Issues

List documents

Users should be able to list documents within a collection without the need to do any queries.

Ideally this should be paginated

โญ - Decouple Nest from the ORM

What would you love to see in the library?

I'd like to be able to use this library even if I don't have NestJS installed, in order to have a higher impact in the Firestore community.

Any solutions in mind?

Leave only code not related to NestJS in this repo and move the related code to a different repo.
Then, rename this repo to something like firestore-orm

Batch operations

Users should be able to do batch operations within a repository or across multiple repositories.

I still don't know a good way to do this

Update Document

Add the method update to the repository which will call Firestore's update method.

Transactions

Users should be able to use transactions within a repository or across multiple repositories.

I still don't know a good way to do this ๐Ÿ‘Ž

So any discussions are welcome

Query (where) document

Add the method update to the repository which will call Firestore's update method.

Ideally, this should have an easy to use paging pattern

Set Document

Add the method update to the repository which will call Firestore's set method.

Pagination

Users should be able to paginate their collections.

There should also be a mechanism where users can iterate over multiple documents, without the need to repaginate.

E.g

// returns an object containing { documents: Cat[] = [..., Cat({ name: 'kitty' })] }
const cats: Page<Cat> = this.repostiory.list({ limit: 50, orderBy: name }) 

// Ideally, Page should be an Iterator, so users could use loop operations over it with no problems.
// This would give users the capacity of iterating over the 50 cats.
for (const cat of cats) { } // iterate over 50 cats

// The Page class should have a method like "iterateAll" that would get the last value of the cats page and query again for the next 50 cats.
cats.iterateAll() // iterates over all cats in the collection, but will query 50 by 50.
  • Add pagination to where query

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.