couchdb-web-node-plugin
Version:
A couchdb server, model instance conflict handler, rest api, authentication, session management, schema validator and model relation guarantee for webNode.
66 lines (47 loc) • 4.09 kB
Markdown
<!-- !/usr/bin/env markdown
-*- coding: utf-8 -*-
region header
Copyright Torben Sickert (info["~at~"]torben.website) 16.12.2012
License
-------
This library written by Torben Sickert stand under a creative commons naming
3.0 unported license. See https://creativecommons.org/licenses/by/3.0/deed.de
endregion -->
Project status
--------------
[](https://www.npmjs.com/package/couchdb-web-node-plugin)
[](https://www.npmjs.com/package/couchdb-web-node-plugin)
[](https://github.com/thaibault/couchdb-web-node-plugin/actions/workflows/build.yaml)
[](https://github.com/thaibault/couchdb-web-node-plugin/actions/workflows/build-package-and-push.yaml)
[](https://github.com/thaibault/couchdb-web-node-plugin/actions/workflows/check-types.yaml)
[](https://github.com/thaibault/couchdb-web-node-plugin/actions/workflows/lint.yaml)
[](https://github.com/thaibault/couchdb-web-node-plugin/actions/workflows/test-coverage-report.yaml)
[](https://coveralls.io/github/thaibault/couchdb-web-node-plugin)
[](https://github.com/thaibault/couchdb-web-node-plugin/actions/workflows/deploy-web-documentation.yaml)
[](https://torben.website/couchdb-web-node-plugin)
Use case
--------
PouchDB with model specification/checking, user authentication and right
management as web-node plugin.
Foreign Key management
----------------------
The plugin provides a foreign key management for PouchDB. It allows to define
foreign keys in the model specification and automatically checks the existence
of the referenced documents when creating or updating documents. It also
provides a way to automatically delete or update the referenced documents when
the referencing document is deleted or updated.
### Mechanism
#### Initialization
During application start the plugin analyzes the model specification and
creates a map of model types to properties that are defined as foreign keys and
which model type they reference.
It than goes through all documents having referencing properties and checks if
the referenced documents exist. If not, it deletes the reference and if yes, it
stores the reference in an internal map of referenced documents to referencing
documents.
#### Document creation and update
When creating or updating a document, the plugin checks if the document has
referencing properties. If yes, it checks if the referenced documents exist. If
not, it deletes the reference and if yes, it stores the reference in the
internal map of referenced documents to referencing documents. It also removes
references from the internal map if they are no longer present.