Database

Database classes provide persistence for Viper C++ documents using SQLite or remote connections.

When to use: Use Database for simple key-value persistence without history tracking. For the mutation DAG, see Commit Database.

Quick Start

from dsviper import Database, DSMBuilder

# Create or open database
db = Database.create("data.vdb")

# Load definitions from DSM
builder = DSMBuilder.assemble("model.dsm")
report, dsm_defs, defs = builder.parse()
db.extend_definitions(defs)

# Write (requires transaction)
db.begin_transaction()
db.set(attachment, key, document)
db.commit()

# Read
result = db.get(attachment, key)
if not result.is_nil():
    doc = result.unwrap()

# Delete
db.begin_transaction()
db.delete(attachment, key)
db.commit()

See also

For detailed examples with concrete attachments, see Database.

Choosing the Right Class

Use Case

Class

Note

Simple CRUD, no history

Database

Creates .vdb files

Need version history

CommitDatabase

See Commit Database

Remote database access

DatabaseRemote

Client-server mode

See also

To copy a Database, or move content to and from a CommitDatabase, see Database Transfer.

Core Classes

dsviper.Database

A Database is a CRUD like transactional database.

dsviper.DatabaseSQLite

A low-level class used to represent a CRUD like database based on SQLite3 through the Databasing interface.

dsviper.DatabaseRemote

A low-level class used to access a CRUD like database from a remote repository through the Databasing interface.

dsviper.Databasing

An interface used to abstract the implementation of the persistence layer for a CRUD like database.

Low-Level

dsviper.SQLite

A class used to retreive the configuration of SQLite3.