addRelation method

  1. @override
void addRelation(
  1. Relation relation, {
  2. bool replaceIfExists = true,
})
override

Add a new relation to the graph

Implementation

@override
void addRelation(Relation relation, {bool replaceIfExists = true}) {
  if (!replaceIfExists && relationExists(relation.id)) {
    return;
  }
  final row = _relationToRow(relation);
  _transaction(() {
    if (replaceIfExists) {
      _db.execute('DELETE FROM relations WHERE id = ?', [relation.id]);
      _db.execute(
        'DELETE FROM relation_properties WHERE relationId = ?',
        [relation.id],
      );
    }
    _db.execute(
      'INSERT INTO relations '
      '(id, type, fromNodeId, toNodeId, labelProperty) '
      'VALUES (?, ?, ?, ?, ?)',
      row,
    );
    _saveRelationProperties(relation.id, relation.properties);
  });
}