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!
In your Nest generated project, run
$ npm i --save nestjs-firestore @google-cloud/firestore
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);
}
}
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' });
}
}
Check the .github/contributing.md
file to learn how to contribute including
steps to build the project and the guidelines for contributing
maddy020 📖 |
Giulio Denardi 💻 📖 🤔 🚧 📆 |
nestjs-firestore is MIT licensed.