1.0.1 • Published 2 years ago

@dotrun/gae-js-firestore v1.0.1

Weekly downloads
159
License
MIT
Repository
-
Last release
2 years ago

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);
  }
}
1.0.1

2 years ago

1.0.0

2 years ago

0.4.4

2 years ago

0.4.7

2 years ago

0.4.6

2 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.3.0

3 years ago

0.3.1

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.0.27

3 years ago

0.0.26

3 years ago

0.0.24

3 years ago

0.0.25

3 years ago

0.0.20

3 years ago

0.0.21

3 years ago

0.0.22

3 years ago

0.0.23

3 years ago

0.0.18

3 years ago

0.0.19

3 years ago

0.0.15

3 years ago

0.0.16

3 years ago

0.0.17

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago