List all models

10 views
Skip to first unread message

Mark Lester

unread,
Jul 2, 2020, 4:34:11 PM7/2/20
to Sequelize
I want to iterate through all model defs, essentially so I can ask Finale to create the REST for them all (unless they have been flagged/unflagged to be exposed and also possibly subject to some milestones)
What is the nice way in latest Sequelize to iterate through all the models.

Mark Lester

unread,
Jul 3, 2020, 6:06:11 AM7/3/20
to Sequelize
this is a forEachModel iterator method.
Really great work everybody with the latest release.

I am going to re implement my 4 simple links
1. loader to read <model name>,js files from a  /models directory. These include a relations block and so I can just go sequelize.LoadModels().then() and be done.
2. get Finale to generate api for all models, unless unflagged
3. get the root of the api to print an array of model definitions, including arbitrary extra config you can put in 1. at both attribute and table level, e.g colour, you could specify a default colour for this attribute if you wanted. (I've had blazing rows about where a default colour value should or should not go) 
4. get the client backbone app to instigate a dictionary of model and collection definitions from the collection at /api/, and in turn create a directory of default collections for each model which can be used within ViewPoint views described here

5. a generic View in Marionette that
    5.1 is instigated with a model or collection instance via name from the above dictionary
    5.2 pre parses templates for
       <ViewPoint model="mymodel" [template="a template"] [view="view extdension"] [collection]>
          or you can have the template code inline here
       </ViewPoint>
   and attach views accordingly

I then have a basic framework whereby you just put files in the models and templates directories and can establish a basic application. The first four, just getting the defs over to backbone and all the api farmed out by default, are trivial quite tiny pieces of code. The magic ViewPoint generic view is slightly more involved but not by much.

I have all this stuff, it just needs cleaning up and as it's a new job I will attempt to push these things out as individual components. If you are aware of anything or any frameworks out there worth having a look at, if only for concepts to copy, please shout. I looked at Sails but not long once I discovered it is bound to Waterfront. I share concerns you may have about all embracing frameworks. You need to be able to control whats going on. At the same time, we have PHP refugees coming from Laravel wondering where the push button stuff is. I have been spending the last few weeks working out how I should re-invent the sea of legacy PHP in front of me and have decided I am doing them a greater service by injecting some Node into their code base. PHP is fun and has served us well and will be here long after all of us have logged out. But you just end up with people generating blocks of javascript. The killer though is the difference between Node/NPM codebase size and rate of dev, compared to PHP land.  It's quite stark.


Reply all
Reply to author
Forward
0 new messages