Client Extension API reference
List of all available methods on an Bark extended Prisma client.
Good to know
Bark doesn't override any of the existing Prisma model queries but it is strongly recommended to create / delete new nodes using the extensions API otherwise the tree structure might not work and require a lot of manual intervention to untangle it. For similar reasons it's best not to directly update path
, numchild
, and depth
properties.
Extend a Prisma Client
To extend a Prisma Client you only have to import Bark and call it with the Bark-compatible models passed into the modelNames
property.
Create
createRoot
createRoot
Creates a root node if one doesn't exist already or adds a sibling to an already existing one. Returns the newly create node entry.
createChild
createChild
Creates a new child to the defined node in either where
or node
arguments. Returns the newly create node entry.
createSibling
createSibling
Creates a new sibling to the defined node in either where
or node
arguments. The node will be created at after last sibling of the level. Returns the newly create node entry.
Find
findTree
findTree
Returns all nodes in tree, including the parent if provided. By default the tree is ordered by path
in ascending order.
findAncestors
findAncestors
Returns all ancestors, from the root node to the parent, of the defined node in either where
or node
arguments. If the findAncestors
called on a root node it will return null
. By default the tree is ordered by path
in ascending order.
findDescendants
findDescendants
Returns all descendants, excluding itself, of the defined node in either where
or node
arguments. If the findDescendants
called on a leaf node it will return null
. By default the tree is ordered by path
in ascending order.
findParent
findParent
Return the parent node of the defined node in either where
or node
arguments. If the findParent
called on a root node it will return null
.
findChildren
findChildren
Returns all direct children nodes of the defined node in either where
or node
arguments. When no children were found it will return null
. By default the tree is ordered by path
in ascending order.
findSiblings
findSiblings
Returns all sibling nodes, including itself, of the defined node in either where
or node
arguments. By default the tree is ordered by path
in ascending order.
findLastRoot
findLastRoot
Returns the last root node. If no root node exist it returns null
.
Delete
deleteNode
deleteNode
Deletes the node and all its descendants. Returns the count of deleted nodes just like deleteMany
would.
deleteManyNodes
deleteManyNodes
Deletes all matching nodes found by the where
filter and their descendants using the least number of operations. Returns the count of deleted nodes just like deleteMany
would. If no nodes were deleted it will return null
.
Operation
move
move
Move the node of the defined node in either where
or node
arguments relative to the reference
's node and the position
argument. Throws if the targeted node is trying to be moved to own of its descendants, if the node is already in the requested position, or if either the target or the referenced node is not found. Returns undefined
fixTree
[TBD]
fixTree
[TBD]Not currently implemented. See issue on GitHub to make your voice heard, or have a go at it.
Helpers [TBD]
These would serve as a syntactic sugar to help make repetitive task easier. An example function be isDescendantOf
, a function that would compare a node to another return true if it's, well, a descendant of it. Let us know what helpers function you'd find useful on the dedicated GitHub issue.
Last updated