Tree object¶
-
class
Tree
(connection=None, pool=None, node_factory=<class 'libtree.node.Node'>)¶ Context manager for creating thread-safe transactions in which libtree operations can be executed.
It yields a
libtree.transaction.Transaction
object which can be used for accessing the tree. When the context manager gets exited, all changes will be committed to the database. If an exception occured, the transaction will be rolled back.It requires either a
connection
orpool
object from the psycopg2 package.When libtree is used in a threaded environment (usually in production), it’s recommended to use a pool object.
When libtree is used in a single-threaded environment (usually during development), it’s enough to pass a standard connection object.
By default the built-in
libtree.node.Node
class is used to create node objects, but it’s possible to pass a different one vianode_factory
.Parameters: - connection (psycopg2.connection) – psycopg2 connection object
- pool (psycopg2.pool.ThreadedConnectionPool) – psycopg2 pool object
- node_factory (object) – Factory class for creating node objects
(default:
libtree.node.Node
)
-
close
()¶ Close all connections in pool or the manually assigned one.
-
make_transaction
()¶ Get a new transaction object using a connection from the pool or the manually assigned one.