Database Class
Database
Contains all the database access methods.
Item Index
Methods
- _get_driver
- _get_session
- _hygiene
- _remove_constraints
- add_comment_to_fragment
- add_constraints
- add_edge
- add_edge
- add_fragment
- add_image
- add_node
- get_all_completed_fragments
- get_all_fragments
- get_all_images
- get_all_property_keys_for_token
- get_all_property_values_for_token
- get_fragment
- get_fragment_bounding_box
- get_fragment_by_id
- get_fragments_by_image_id
- get_image
- get_image_of_token
- init
- log_error_and_close_session
- login
- logout
- remove_fragment
- remove_image_by_id
- toggle_fragment_completed
Properties
Methods
_get_driver
()
Driver
private
Get the database driver stores the instance in _driver makes use of the development flag in order to use or not use basic auth
Returns:
Returns a bolt:// driver instance
_get_session
()
Session
private
Get a session to execute Neo4J Cypher code on
Returns:
_hygiene
()
Promise
Clean up the database on login
- remove nodes without edges (-> MetaGroups that are not referenced)
Returns:
_remove_constraints
()
Promise
private
Remove the constraints
Returns:
add_comment_to_fragment
-
fragment_id -
comment
Sets the comment attribute of a fragment
Parameters:
-
fragment_idObject -
commentObjectstring
Returns:
add_constraints
()
Session
Add the necessary constraints to create something like a schema
- The file_path of an image is unique
Returns:
add_edge
-
image_id -
fragment_id -
source_enum -
target_enum -
edge_attributes
Adds an edge between two nodes in a fragment of an image
Promise:success number_of_created_edges
Parameters:
-
image_idObject -
fragment_idObject -
source_enumObject -
target_enumObject -
edge_attributesObject
Returns:
add_edge
-
node_id -
frame_name -
groupType
Adds an edge between a frame from a group and a global frame so called 'meta frame'
Also creates the 'meta frame' if it does not exist *
Parameters:
-
node_idObject -
frame_nameObject -
groupTypeObject
Returns:
add_fragment
-
image_id -
fragment_name
Adds a fragment to an image Every image can have multiple fragments the name of the fragment is unique
Parameters:
-
image_idObject -
fragment_nameObjectThe identifier for the fragment
Returns:
add_image
-
file_path -
exif_data
Adds an image to the database Sets attributes according to the exif_data Fallback for upload_date is now in seconds (Math.round(d.getTime()))
The exif_data shall be an objects with the attributes 'exif: { 'ExifImageWidth': ..., 'ExifImageHeight': ..., 'CreateDate': ... }, 'gps: {...}
CreateDate is handled by the parse(...) function
Parameters:
-
file_pathStringThe unique identifier for an image
-
exif_dataObject
Returns:
add_node
-
image_id -
fragment_id -
node_label -
node_attributes
Adds a node to a fragment of an image
Promise:success number_of_created_nodes
Parameters:
-
image_idObject -
fragment_idObject -
node_labelObject -
node_attributesObject
Returns:
get_all_completed_fragments
()
| Promise
Get all completed fragments
Returns:
get_all_fragments
()
Promise
Get the fragment of an image by name
Returns:
get_all_images
()
Promise
Returns a promise with an array of records of images ordered by last_edit_date, upload_date
Returns:
Example:
database.get_all_images().then(function (results) {
var row_data = [];
results.forEach(function (r) {
row_data.push([r.get('ident'), r.get('file_path'), r.get('upload_date'), r.get('completed')]);
});
res.render('table',
{
title: 'Hey',
message: 'Hello there!',
rows: row_data
});
}
);
get_all_property_keys_for_token
-
search_string -
label -
token_type
Returns all possible property keys for tokens filtered by search_string Is used for the autocomplete function of the add-property-input
Promise:success: Array of strings
Parameters:
-
search_stringStringEmpty string gives all possible values
-
labelObject -
token_typeObject
Returns:
get_all_property_values_for_token
-
property -
search_string
Returns all distinct values for the given property in a string list in a promise Is used for the autocomplete function of the property values
Promise:success: Array of strings *
Parameters:
-
propertyStringthe name of a property of tokens
-
search_stringStringthat filters the result (empty string is not filter)
Returns:
get_fragment
-
image_file_path -
fragment_name
Get the fragment of an image by name
Parameters:
-
image_file_pathStringThe unique id for the image
-
fragment_nameObjectThe identifier for the fragments
Returns:
get_fragment_bounding_box
-
token_id
Get the bounding box of a fragment
This method looks for the lowest x and y coordinates of all sibling tokens and for the highest x and y coordinates of all siblings
Used for heat map generation
Parameters:
-
token_idIntThe unique identifier for a token
Returns:
get_fragment_by_id
-
image_id -
fragment_id
Get the fragment of an image by name
Parameters:
-
image_idObject -
fragment_idObject
Returns:
get_fragments_by_image_id
-
image_id
Get all fragments of one image
Parameters:
-
image_idObject
Returns:
get_image
-
file_path
Get image from database by file_path
Promise: success: Contains record for the image
Parameters:
-
file_pathStringThe unique identifier for an image
Returns:
get_image_of_token
-
token_id
Get the image of a token
Parameters:
-
token_idIntThe unique identifier for a token
Returns:
init
()
Session
Do the initialization on start
- drop and then create constraint
Returns:
log_error_and_close_session
()
Error
Generic catch error function for database promises Logs the error and closes the db session
Returns:
login
-
url -
user -
password
Try to fetch a neo4j driver with the given credentials if that works, the Database._driver is not null anymore. It also set the Database.logged_in to true
Parameters:
-
urlStringthe endpoint of neo4j
-
userString -
passwordString
Returns:
logout
()
Boolean
Logout from the current database neo4j session. Delete the saved neo4j session and set the Database.logged_in flag to false.
Returns:
remove_fragment
-
image_id -
fragment_id -
dont_delete_fragment
Removes a fragment of an image or makes it empty
This method not only deletes the fragment but also its children
Parameters:
-
image_idObject -
fragment_idObject -
dont_delete_fragmentObjectActivate this option to delete only the children
Returns:
remove_image_by_id
-
id_
Removes an image by ID
Parameters:
-
id_String | Number
Returns:
toggle_fragment_completed
()
Promise
Toggle the completed status of a fragment The status is used for the batch-add functionality
Returns:
Properties
_driver
Driver
private
Stores the neo4j-driver for the method <_get_driver>
Default: null
_logged_in
Boolean
Stores whether a successful login took place
Default: false
development
Boolean
The development flag controls the basic auth credentials
Default: false
