Client Extension API reference
List of all available methods on an Bark extended Prisma client.
Last updated
List of all available methods on an Bark extended Prisma client.
Last updated
Bark doesn't override any of the existing 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.
To extend a Prisma Client you only have to import Bark and call it with the Bark-compatible models passed into the modelNames
property.
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.
data
Yes*
Object that will be used to create new record in database.
...args
No
createChild
Creates a new child to the defined node in either where
or node
arguments. Returns the newly create node entry.
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
data
Yes*
...args
No
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.
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
data
Yes*
...args
No
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.
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
orderBy
No
Lets you order the returned list by any property. Defaults to { path: 'asc' }
...args
No
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.
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
orderBy
No
Lets you order the returned list by any property. Defaults to { path: 'asc' }
...args
No
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
.
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
...args
No
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.
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
orderBy
No
Lets you order the returned list by any property. Defaults to { path: 'asc' }
...args
No
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.
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
orderBy
No
Lets you order the returned list by any property. Defaults to { path: 'asc' }
...args
No
findLastRoot
Returns the last root node. If no root node exist it returns null
.
...args
No
deleteNode
node
Yes unless where
An existing node used as a reference where the incoming entry should be created.
where
Yes unless node
Query to find an existing node to be used as a reference.
deleteManyNodes
where
Yes
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
node
Yes unless where
An existing node used as a reference where the incoming entry should be move.
where
Yes unless node
Query to find an existing node to be used as a reference.
position
Yes
One of the following: first-child
, last-child
, first-sibling
, left
, right
, or last-sibling
reference.node
Yes unless reference.where
An existing node used as a reference point to move.
reference.where
Yes unless reference.node
Query to find an existing node to be used as a reference.
fixTree
[TBD]Same as options excluding data
.
Object that will be used to create new record in database. Same as except path
, depth
, and numchild
Same as options excluding data
.
Object that will be used to create new record in database. Same as except path
, depth
, and numchild
Same as options excluding data
.
Same as options excluding where
and orderBy
.
Same as options excluding where
and orderBy
.
Same as options excluding where
.
Same as options excluding where
and orderBy
.
Same as options excluding where
Same as options excluding where
and orderBy
.
Deletes the node and all its descendants. Returns the count of deleted nodes just like would.
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 would. If no nodes were deleted it will return null
.
Same as
Not currently implemented. to make your voice heard, or have a go at it.
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 .