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 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.
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.
Argument | Required | Description |
---|---|---|
createChild
Creates a new child to the defined node in either where
or node
arguments. Returns the newly create node entry.
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.
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
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
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
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
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
Returns the last root node. If no root node exist it returns null
.
deleteNode
Deletes the node and all its descendants. Returns the count of deleted nodes just like deleteMany
would.
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
.
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]Not currently implemented. See issue on GitHub 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 GitHub issue.
Argument | Required | Description |
---|---|---|
Argument | Required | Description |
---|---|---|
Argument | Required | Description |
---|---|---|
Argument | Required | Description |
---|---|---|
Argument | Required | Description |
---|---|---|
Argument | Required | Description |
---|---|---|
Argument | Required | Description |
---|---|---|
Argument | Required | Description |
---|---|---|
Argument | Required | Description |
---|---|---|
Argument | Required | Description |
---|---|---|
Argument | Required | Description |
---|---|---|
data
Yes*
Object that will be used to create new record in database.
...args
No
Same as create
options excluding data
.
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*
Object that will be used to create new record in database. Same as create.data
except path
, depth
, and numchild
...args
No
Same as create
options excluding data
.
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*
Object that will be used to create new record in database. Same as create.data
except path
, depth
, and numchild
...args
No
Same as create
options excluding data
.
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
Same as findMany
options excluding where
and orderBy
.
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
Same as findMany
options excluding where
and orderBy
.
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
Same as findUnique
options excluding where
.
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
Same as findMany
options excluding where
and orderBy
.
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
Same as findMany
options excluding where
...args
No
Same as findFirst
options excluding where
and orderBy
.
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.
where
Yes
Same as findMany.where
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.