0.1.0 • Published 3 years ago

onfirework v0.1.0

Weekly downloads
17
License
BSD-2-Clause
Repository
github
Last release
3 years ago

Firebase for dummies.

npm

Easiest way to access to Cloud Firestore collections

Install

npm install onfirework --save

Example usage

import * as firebase from 'firebase-admin';
import { Onfirework, Filter, Result } from 'onfirework';

interface BikeSchema {
  BRAND: string,
  MODEL: string,
  COLOR: string,
  HORSE_POWER: number,
  CATEGORY: string[],
  PRICE: number
}

firebase.initializeApp();
let db = firebase.firestore();

const bikes = new Onfirework<BikeSchema>(db, 'BIKES')

/**
 * Select all docs from BIKES collection where BRAND is Ducati and HORSE_POWER greater or equal to 70 and PRICE greater to 8000
 */
async function listBikes() {
  
  const where:Filter<BikeSchema>[] = [
    ['BRAND', '==', 'Ducati'], 
    ['HORSE_POWER', '>=', 70],
    ['PRICE', '>', 8000]
  ]
  const ducati:Result<BikeSchema>[] = await bikes.listDocs(where)

  console.log(ducati)
}

Available methods

createDoc(data: Partial<Inreface>, id?: DocumentReference): Promise<void>

Add a new document to this collection with the specified data.

If the DocumentReference is not passed it will be created automatically.

readDoc(id: DocumentReference): Promise<Result<Interface>>

Read the document referred to by this DocumentReference.

updateDoc(id: DocumentReference, data: Partial<Inreface>): Promise<void>

Updates fields in the document referred to by this DocumentReference.

The update will fail if applied to a document that does not exist.

updateDocs(filter: [FieldPath, WhereFilterOp, any][], data: Partial<Inreface>): Promise<void>

Update documents according to filtering.

deleteDoc(id: DocumentReference): Promise<void>

Deletes the document referred to by this DocumentReference.

deleteDocs(filter?: [FieldPath, WhereFilterOp, any][]): Promise<void>

Delete documents according to filtering.

If the filter is not passed, it will remove all documents.

listDocs(filter?: [FieldPath, WhereFilterOp, any][], limit?: Number): Promise<Result<Interface>[]>

Reads documents according to filtering.

If the filter is not passed, it will show all documents.

SELECT * FROM foo

foo.listDocs()
SELECT * FROM foo LIMIT 2

foo.listDocs([], 2)
SELECT * FROM foo WHERE foo.BRAND = 'Ducati' AND foo.COLOR = 'White' LIMIT 2

foo.listDocs([['BRAND', '==', 'Ducati'], ['COLOR', '==', 'White']], 2)
listFirst(filter?: [FieldPath, WhereFilterOp, any][]): Promise<Result<Interface>>

Gets first document according to filtering.


License

The project is licensed under the BSD License.

0.1.0

3 years ago

0.0.15

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.12

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

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago