prodo-dev / prodo

Prodo is a React framework to build apps faster.
https://docs.prodo.dev
MIT License
114 stars 5 forks source link

DB plugin queries #63

Closed coffee-cup closed 5 years ago

coffee-cup commented 5 years ago
export interface Query<T> {
  where?: [
    [keyof T, firebase.firestore.WhereFilterOp, any], // field, op, value
  ];
  orderBy?: [[keyof T] | [keyof T, "asc" | "desc"]];
  limit?: number;
}

This plugin is not finalized yet as it isn't testable. The next step is to allow passing in fixtures that can mock firestore.

Type of Collection is

export interface Collection<T extends { id: string }> {
  ref: (key: string) => firebase.firestore.CollectionReference;

  // methods for actions
  get: (id: string) => Promise<T>;
  getAll: () => Promise<T[]>;
  set: (id: string, value: Partial<T>) => Promise<void>;
  delete: (id: string) => Promise<void>;
  insert: (value: Omit<T, "id">) => Promise<string>;
  query: (query: Query<T>) => Promise<T[]>;

  // methods for react components
  watch: (id: string) => Fetching<T>;
  watchAll: (query?: Query<T>) => FetchAll<T>;
}