2

I'm using ArangoDB 3.4 and planning to use an MVC framework like Backbone.js (or whatever is recommended). Is there a way to auto-generate the models from the existing database to reduce the amount of boilerplate code I have to write by hand?

For example, I am looking at the aye-aye TodoMVC demo. It has this model:

const joi = require('joi');

exports.Model = {
  _key: joi.string().optional(),
  _id: joi.string().optional(),
  _rev: joi.string().optional(),
  completed: joi.boolean().optional(),
  order: joi.number().optional(),
  title: joi.string().optional()
};

Writing a few by hand is no problem. My database will ultimately require many of these models. Are there any tools that I can use with ArangoDB that will help automate this by producing scaffold code?

What I have in mind is possibly something like Python's inspectdb command:

inspectdb

Introspects the database tables in the database pointed-to by the DATABASE_NAME setting and outputs a Django model module (a models.py file) to standard output.

Use this if you have a legacy database with which you'd like to use Django. The script will inspect the database and create a model for each table within it.

As you might expect, the created models will have an attribute for every field in the table.

If there are entirely different approaches to doing this with ArangoDB and javascript please point me in the right direction.

Community
  • 1
  • 1
BugBuddy
  • 576
  • 2
  • 5
  • 19

1 Answers1

2

django-admin inspectdb [table [table ...]] targets relational databases where tables have schema and because of that it's possible to generate model

ArangoDB is NoSQL with schemaless collections with ability to store various JSON documents types and because of that you'll need to get schema per document type.

While using fullstack javascript approach you can put your model in js module and use it on both front and backend.

for us, most reliable and scalable approach is based on Typescript as master with following-ish workflow

then you can

  • generate JSON Schema via typescript-json-schema
  • generate UML diagram with tsviz
  • convert JSON Schema to joi with enjoi
  • generate forms from JSON schema (front-end framework specific)
sevcik.tk
  • 514
  • 4
  • 7
  • which frontend frameworks would be compatible with that approach? I have zero experience, so I will use whatever is recommended. I use Atom editor. Would this be a good guide to follow? http://blog.wolksoftware.com/working-with-react-and-typescript – BugBuddy Dec 22 '18 at 21:50
  • any FE FW gonna be compatible with that approach, as same as, that any FW gonna have pros and cons. I started years ago with Angular, because it had best ecosystem with plugins covering all needs, but learning curve was steep, plugins were not kept up to date and syntax was unnatural with high cognitive load. React, Vue are mixing html, js and css, that locks you in their way while loosing things like battle proved html, sass approach and tooling. That's why we use Aurelia. Try few FW and pick what feels natural to you. As IDE I recommend VS Code cause it's faster, smarter and <3 TypeScript – sevcik.tk Dec 23 '18 at 02:12
  • I believe you mean json2ts, not jsontots: http://json2ts.com/ – Avi Nerenberg Aug 20 '21 at 01:16
  • 1
    Hi @AviNerenberg, thanks for correct the link, I did update answer, not sure if it was functional in 2018 or if it was typo... – sevcik.tk Aug 20 '21 at 05:34