# The Python Connection Class

> The Connection class provides the following methods to manage the database Connection, Transactions and Cursors:

> close()
> Close this connection; the connection object becomes invalid
> startTransaction(type, priority)
> Start a database transaction on this connection
> commit()
> Commit an open transaction on this connection
> rollback()
> Rollback the database changes made in the current transaction
> createBackup(filename, label, type, compression_level, cipher)
> Create an incremental backup record in the specified file
> restoreBackup(filename, label, cipher)
> Restore the database from an incremental backup in the specified file up to the specified label
> deleteAll(clsDesc)

> Delete all objects of the class `clsDesc` (the class description, either as a string or the class type taken from the Dictionary object) For example, the following two calls are equivalent:

>         >>>conn.deleteAll(‘myclass’)
>         >>>conn.deleteAll(dict.classes[‘myclass’])

> new(clsName)
> Create new object in the database using the schema definition for class `clsName`
> waitEvent(eventId)
> Start waiting for an asynchronous event specified by argument `eventId` (Normally this is called from a separate event-handler thread)
> releaseAllEvents()
> Release all events and stop the event handler threads
> remove(obj)
> Remove an object `obj` from the database. The object argument `obj` must be taken from one of the Cursor operations `find()` or `search()` executed on this connection
> cursor(cls, idx)
> Create a cursor for retrieving data on this connection
> getStats()

> Get database statistics; it returns a dictionary containing keys with the following database information:

>         TotalPages
>         FreePages
>         PageSize

> For persistent databases it also contains dictionary keys with the disk file statistics:

>         DataFileSize
>         LogFileSize
>         UsedDatabaseSize

> getClassStats(cls)

> Get class `cls` statistics from the database; iIt returns a dictionary containing the following keys:

>         ObjectsNum
>         VersionsNum
>         CorePages
>         BlobPages
>         CoreSpace

> getIndexStats(idx)

> Get index `idx` statistics from the database; it returns a dictionary containing the following keys:

>         ClassCode
>         Type
>         Label
>         KeysNum
>         PagesNum
>         AvgChainLength – for hash indexes only
>         MaxChainLength - for hash indexes only
>         LevelsNum – for tree indexes only
>         DuplicatesNum  - for tree indexes only
>         DiskPagesNum

> getDiskCacheInfo()

> Get disk cache statistics; it returns a dictionary containing the following keys:

>         connection_cache_hits
>         cache_hits
>         cache_misses
>         allocated_pages
>         used_pages
>         pinned_pages
>         modified_pages
>         dirty_pages
>         copied_pages
>         write_delayed_pages
>         subsequent_reads

> saveSnapshot(path, saveMetadata=True, saveCRC=True)
> Perform a snapshot image of the database to a disk file specified by path arguments
> nest()

> The method inserts records

> Available since eXtremeDB version 8.4.1806.

> db
> A Read-Only property specifying the database on which this connection is opened
> engine
> A Read-Only property specifying the SQL engine for this connection