Skip to content

Repository files navigation

FireBorm

A Firebase ORM-like wrapper, inspired by packages like sequelize and mongoose.

Why?

Using the firebase sdk to fetch data from Firestore and transform it to the model we use on the apps can sometimes be verbose.

This package solves this issue using an approach inspired in sequelize or mongoose.

Usage

Initializing fireborm also handles the firebase initialization, as well as emulators initialization.

// ./index.tsimport{FireBorm}from'fireborm'// Firebase config fileimport{firebaseConfig}from'../../firebase-config'// Initialize Fireborm singletonconstfireborm=newFireborm(config,settings)

Stores

Stores correspond to Collections. The store class provides end-to-end type hinting without much hassle.

Declare a store by calling fireborm.createStore() and providing the arguments.

// ./store.tsexportconstMyStore=fireborm.createStore<DocumentSchema,// Shape of the document in FirebaseModelSchema,// Shape of the transformed document, used in the appCreationSchema,// Shape of the minimum required data for creationDefaultSchema// Shape of the default object data>({path: 'path-without-spaces',plural: 'Plural name',singular: 'Singular name',defaultData: {// as DefaultSchema, or DocumentSchema if omitedid: crypto.randomUUID(),name: '',createdAt: newDate()},toModel: document=>({// Transforms DocumentSchema to ModelSchema
...document.data(),id: document.id}),toDocument: ({ id, ...model})=>{// Transforms ModelSchema to DocumentSchemareturnmodel}})

Then use the store in any file like:

// ./component.tsxstore.count({onChange: count=>setCount(count)})useEffect(()=>{store.subscribeMany({onChange: res=>setData(res)})},[store,getQuery])

Storages

Each Storage corresponds to a collection.

You declare each storage by calling fireborm.initializeStorage() and providing the arguments.

More information about the arguments, and the class returned will be added soon.

About

A Firebase ORM-like wrapper, inspired by packages like sequelize and mongoose

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages