Schemaless - abstractfactory/cquery GitHub Wiki

cQuery for schemaless directory structures.

cQuery can be used as an alternative to defining schemas for directory hierarchies within a project. Examples include feature animation projects in which a facility may work on multiple projects, containing multiple assets with multiple sub-assets each.

/projects/spiderman/content/assets/Peter
/projects/spiderman/content/assets/Mary

Traditionally, one may pre-determine the location of asset-type content.

{"assets": "/projects/spiderman/content/assets"}

For per-project schemas, it would then be a matter of removing the project-specific path from the absolute path and resolve this at run-time.

/projects/spiderman/schema.json

{"assets": "content/assets"}

Thus far all is well. The issue arises when the number of custom types starts to increase.

{
    "assets": "content/assets",
    "shots": "content/shots",
    "content": "content",
    "lightrigs": ["content/assets/Peter/rigs/light", "content/assets/Mary/rigs/light"],
    "animrigs": ["content/assets/Peter/rigs/anim", "content/assets/Mary/rigs/light"]
}

At this point, all is still well, but the re-usability has been limited to projects utilising these exact types. To make matters worse, altering or removing entries may cause software depending on the exact schema to break or silently misbehave.

Schemaless

/projects/spiderman/content/assets/Peter # Asset
/projects/spiderman/content/assets/Mary # Asset
/projects/spiderman/content/shots/1020 # Shot
/projects/spiderman/content/shots/2100 # Shot
/projects/spiderman/content/shots/3000 # Shot
/projects/spiderman/content/assets/Peter/rigs/lightRigLow # LightRig
/projects/spiderman/content/assets/Peter/rigs/lightRigHigh # LightRig

In this example, each individual asset has been tagged with information describing what type of asset it is. Each asset is, at this point, self-describing. This means we can ask it questions directly:

$ cd /projects/spiderman
$ cquery .Asset
# /projects/spiderman/content/assets/Peter
# /projects/spiderman/content/assets/Mary
$ cquery .LightRig
# /projects/spiderman/content/assets/Peter/rigs/lightRigLow
# /projects/spiderman/content/assets/Peter/rigs/lightRigHigh

The same goes for queries in the opposite direction:

$ cd content/assets/Peter/rigs/lighRigLow
$ cquery .Asset --direction=up
# /projects/spiderman/content/assets/Peter

At this point, content is self-descriptive and can be reshuffled, removed or modified without affecting the code running on it.