Map JSON Documents, Not Programming Objects

A JSON-relational duality view declaratively defines a mapping between JSON documents and relational data. That’s better than mapping programming objects to relational data.

If you use an object-relational mapper (ORM) or an object-document mapper (ODM), or you’re familiar with their concepts, then this topic might help you better understand the duality-view approach to handling the “object-relational impedance mismatch” problem.

Duality views could be said to be a kind of ORM: they too map hierarchical object data to/from relational data. But they’re fundamentally different from existing ORM approaches.

Duality views centralize the persistence format of application objects for both server-side and client-side applications - all clients, regardless of language or framework. The persistence model presents two aspects for the same data: table and document. Server-side code can manipulate relational data in tables; client-side code can manipulate a collection (set) of documents.

Client code need only convert its programming objects to/from JSON, which is familiar and easy. A duality view automatically persists JSON as relational data. There’s no need for any separate mapper - the duality view is the mapping.

The main points in this regard are these:

A duality view maps parts of one or more tables to JSON documents that the view defines - it need not map every column of a table. Documents depend directly on the mapping (duality view), and only indirectly on the underlying tables. This is part of the duality: presenting two different views - not only views of different things (tables, documents) but typically of somewhat different content. Content-wise, a document combines subsets of table data.

This separation/abstraction is seen clearly in the fact that not all columns of a table underlying a duality view need be mapped to its supported documents. But it also means that some changes to an underlying table, such as the addition of a column, are automatically prevented from affecting existing documents, simply by the mapping (view definition) not reflecting those changes. This form of table-level schema evolution requires no changes to existing duality views, documents, or applications.

On the other hand, if you want to update an application, to reflect some table-level changes, then you change the view definition to take those changes into account in whatever way you like. This application behavior change can be limited to documents that are created after the view-definition change.

Alternatively, you can create a new duality view that directly reflects the changed table definitions. You can use that view with newer versions of the application while continuing to use the older view with older versions of the app. This way, you can avoid having to upgrade all clients at the same time, limiting downtime.

In this case, schema evolution for underlying tables leads to schema evolution for the supported documents. An example of this might be the deletion of a table column that’s mapped to a document field. This would likely lead to a change in application logic and document definition.

Related Topics