posva / vuexfire

Check
https://github.com/vuejs/vuefire
MIT License
558 stars 49 forks source link

Feature: Support of Object Data Mapper (ODM) #175

Closed bdiz closed 5 years ago

bdiz commented 6 years ago

Hello, this is somewhat related to my earlier comments in #167. What I've come to learn is that what I was looking for in my app is an ODM layer on top of Vuex, Firestore, vuexfire. Inspired by Mongoid, something like:

// src/store/models/todo.js
import Vue from 'vue';
import { documentMixin } from 'vuexfire';
import SubTask from './sub-task';

export default Vue.extend({
  mixins: [
    documentMixin('todo', {
      fields: ['text'],
      embeddedIn: 'category',
      embedsMany: { // uses firestore subcollection
        subTasks: { model: SubTask }
      }
    })
  ],
  computed: {
    // ...
  }
});

With this you can operate on a todo object ie let todo = Todo.create(...); todo.updateAttribute(...); todo.upsert(...); todo.delete(); todo.category; todo.text; todo.subTasks; todo.subTasks.create(...);.

I've built a working version of this using dynamic modules under the hood, but it needs a lot of work. Before I spend more time on it I thought I'd ask if this was on the road map of vuexfire? Or if there are other libraries you may know about that might just require a vuexfire "adapter" to get working? If their is no such ODM for even firebase, which has been around for a while, is there a flaw in my reasoning as to this being a missing level of abstraction for our Vuex/Firestore apps?

ClickerMonkey commented 5 years ago

Perhaps look into https://github.com/fiery-data/fiery-vuex - this has exactly what you're looking for.

motin commented 5 years ago

Perhaps look into https://github.com/fiery-data/fiery-vuex - this has exactly what you're looking for.

Looks good. A more general, non-firestore-specific library to look into is https://vuex-orm.github.io/vuex-orm/ which may be able to be used with Firestore as a persistency backend using vuexfire / fiery.

posva commented 5 years ago

This is something that goes beyond the scope of vuefire/vuexfire. It could be useful but only for a small amount of people using it, I'm okay with having some discussion around it (in vuefire repo) but I definitely don't have the bandwidth to produce such thing. Theoritically it could be built as a plugin once https://github.com/vuejs/vuefire/issues/240 or https://github.com/vuejs/vuefire/issues/153 get implemented

I'm archiving vuexfire since everything is moved to vuefire, so I'm closing this