This package has been deprecated

Author message:

WARNING: This project has been renamed to @mondomob/gae-js-firestore. Please install using the new package.

@dotrun/gae-js-firestore
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

GAE JS FIRESTORE

Use Firestore in Native mode as your app db including DataLoader implementation GraphQL and request level caching.

Installation

npm install @dotrun/gae-js-firestore

Components

FirestoreProvider

Initialise Firestore to be accessed elsewhere in your app.

// On app startup
firestoreProvider.init();

// Anywhere else in your app
const firestore = firestoreProvider.get();
const doc = await firestore.doc('my-items/id123').get();

FirestoreLoader

Dataloader implementation to help batch and cache db requests. Used internally by FirestoreRepository

// Apply middleware to create a new dataloader on each request
app.use(firestoreLoader());

FirestoreRepository

Access your collections through typed repositories.

// Define your class entity
interface DemoItem {
  id: string;
  name: string;
}

// Initialise repository for the collection we want to access data in
const repository = new FirestoreRepository<DemoItem>("demo-items");

// OR define a custom class first
class DemoItemRepository extends FirestoreRepository<DemoItem> {
  constructor() {
    super("demo-items");
  }
}
const repository = new DemoItemsRepository();

// Save an item
await repository.save({ id: "id123", name: "test item" });

// Get an item
const item = await repository.get("id123");

// Query items
const list = await demoItemsRepository.query();

@Transactional

Annotate functions to make them transactional.

NOTE: Requires "experimentalDecorators": true set in your tsconfig.json

class UserService {
  constructor(
    public userRepo: FirestoreRepository<User>,
  ) {}

  @Transactional()
  async addCredits(userId: string, credits: number): Promise<User> {
    const user = this.userRepo.get(userId);
    user.credits = user.credits + credits;
    return this.userRepo.save(user);
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @dotrun/gae-js-firestore

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

46.7 kB

Total Files

47

Last publish

Collaborators

  • mlevett