Database

A database stores entities and their transactions. Documents and expression programs can operate without a database. The example opens a database, lists its included plugins, and closes it. The plugins option selects the plugins that the database enables. The reactors plugin runs live mutations, and the history plugin purges old history.

License checks

Opening a database checks the active license, its optional expiry, and permissions for the enabled plugins. An open database and its derived handles keep working after expiry or license replacement. See Core activation.

Example

Open a database and retain an independent native document

go251 B
opened, err := stardust.Open(databasePath, stardust.Options{})
if err != nil {
	return err
}

// Closing the database leaves the plugin document valid.
result, err := stardust.Plugins()
opened.Close()
if err != nil {
	return err
}
defer result.Close()
Result / 1.4 kB
[{name            history
  description     History retention: purges entity history by each stardust/history setting
  version         '1'
  willNotWorkWith [backups]
  databaseHooks   true}
 {name          adaptiveQueryPlanner
  description   Adaptive join orders: learns from runs and stores the plans that proved better
  version       '1'
  databaseHooks true}
 {name          objects
  description   Object store: content-addressed payloads in named files and directories
  version       '1'
  databaseHooks true}
 {name            events
  description     Event coordination: temporary publish and subscribe messages beside durable facts
  version         '1'
  definitionTypes [events]
  databaseHooks   true}
 {name            blackholes
  description     Deliberate removal: confirmed and audited rewrite of the history and backups of the fields a blackhole definition selects
  version         '1'
  definitionTypes [blackholes]
  databaseHooks   true}
 {name          reactors
  description   Atomic live mutation derivation
  version       '1'
  databaseHooks true}
 {name          sdk
  description   SDK generation: publishes a typed package of the stored definitions while the database is open
  version       '1'
  databaseHooks true}
 {name          skills
  description   Agent skills generation: publishes skills and reference files for the stored definitions while the database is open
  version       '1'
  databaseHooks true}]

Locking

Opening a database requires the file lock that protects its recorded changes. The lock_timeout option sets how the call waits for that lock:

lock_timeoutResult
ZeroIf the lock is unavailable, the call fails immediately.
PositiveThe call waits up to that duration, rounded up to whole milliseconds.
NegativeThe call waits without limit.

When the wait ends without the lock, the call fails with the locked status. The options table gives the default and the type in your language.

Operations

OperationReturnsSummary
Opendatabaseopen(path, options) opens a database.
Database.ClosenoneRelease the database handle.

Open

go58 B
func Open(path string, options Options) (*Database, error)

Parameters

ParameterTypeOwnershipDefaultMeaning
pathstringValueRequiredThe database file path.
optionsOptionsValueRequired options record. See field defaultsThe operation's options record. See its field defaults.

Errors

StatusWhen
StatusNotFoundthe parent directory is missing, or the file is missing and create is false
StatusLockedanother process holds the lock after lock_timeout
StatusInvalidArgumentthe file is not a database, an option is invalid, selected plugins are incompatible, or a plugin refuses its settings: the error carries the plugin's code (such as unknown_plugin_setting), the plugin's name as its path and the setting at fault as its field (nested settings as dotted member names, ambiguous when a name holds a dot)
StatusConflictan enabled plugin finds the database inconsistent with its copies: backups refuse diverging copies with code backup_history_divergent, naming them
StatusUnavailablean enabled plugin cannot reach what the open needs: backups refuse with backup_targets_unreachable, backup_target_unreadable or backup_objects_required; filesystem refuses with filesystem_fuse_unavailable or filesystem_mount_failed, naming the mount point; the events plugin is required when the database stores event definitions (plugin_required)
StatusUnsupporteda selected plugin has no implementation on this platform: the filesystem plugin on Windows
StatusOutOfMemorynative memory is exhausted

Examples

Open a database and retain an independent native document

go251 B
opened, err := stardust.Open(databasePath, stardust.Options{})
if err != nil {
	return err
}

// Closing the database leaves the plugin document valid.
result, err := stardust.Plugins()
opened.Close()
if err != nil {
	return err
}
defer result.Close()
Result / 1.4 kB
[{name            history
  description     History retention: purges entity history by each stardust/history setting
  version         '1'
  willNotWorkWith [backups]
  databaseHooks   true}
 {name          adaptiveQueryPlanner
  description   Adaptive join orders: learns from runs and stores the plans that proved better
  version       '1'
  databaseHooks true}
 {name          objects
  description   Object store: content-addressed payloads in named files and directories
  version       '1'
  databaseHooks true}
 {name            events
  description     Event coordination: temporary publish and subscribe messages beside durable facts
  version         '1'
  definitionTypes [events]
  databaseHooks   true}
 {name            blackholes
  description     Deliberate removal: confirmed and audited rewrite of the history and backups of the fields a blackhole definition selects
  version         '1'
  definitionTypes [blackholes]
  databaseHooks   true}
 {name          reactors
  description   Atomic live mutation derivation
  version       '1'
  databaseHooks true}
 {name          sdk
  description   SDK generation: publishes a typed package of the stored definitions while the database is open
  version       '1'
  databaseHooks true}
 {name          skills
  description   Agent skills generation: publishes skills and reference files for the stored definitions while the database is open
  version       '1'
  databaseHooks true}]

Open with explicit native options

go177 B
create := true
result := stardust.Options{Create: &create, PageSize: 0}
database, err := stardust.Open(databasePath, result)
if err != nil {
	return err
}
defer database.Close()
Result / 221 B
{create              true
 clear               false
 pin_memory          false
 page_size           0
 lock_timeout        0
 initial_map_bytes   0
 commit_batch        0
 plugins             null
 memory_budget_bytes 0}

Wait for the database lock without a limit

go208 B
create := true
result := stardust.Options{Create: &create, PageSize: 0, LockTimeout: -time.Nanosecond}
database, err := stardust.Open(databasePath, result)
if err != nil {
	return err
}
defer database.Close()
Result / 224 B
{create              true
 clear               false
 pin_memory          false
 page_size           0
 lock_timeout        null
 initial_map_bytes   0
 commit_batch        0
 plugins             null
 memory_budget_bytes 0}

C exports: stardust_db_open, stardust_result_error, stardust_result_release

Database.Close

go26 B
func (d *Database) Close()

Consumes the receiver handle.

Examples

Open a database and retain an independent native document

go251 B
opened, err := stardust.Open(databasePath, stardust.Options{})
if err != nil {
	return err
}

// Closing the database leaves the plugin document valid.
result, err := stardust.Plugins()
opened.Close()
if err != nil {
	return err
}
defer result.Close()
Result / 1.4 kB
[{name            history
  description     History retention: purges entity history by each stardust/history setting
  version         '1'
  willNotWorkWith [backups]
  databaseHooks   true}
 {name          adaptiveQueryPlanner
  description   Adaptive join orders: learns from runs and stores the plans that proved better
  version       '1'
  databaseHooks true}
 {name          objects
  description   Object store: content-addressed payloads in named files and directories
  version       '1'
  databaseHooks true}
 {name            events
  description     Event coordination: temporary publish and subscribe messages beside durable facts
  version         '1'
  definitionTypes [events]
  databaseHooks   true}
 {name            blackholes
  description     Deliberate removal: confirmed and audited rewrite of the history and backups of the fields a blackhole definition selects
  version         '1'
  definitionTypes [blackholes]
  databaseHooks   true}
 {name          reactors
  description   Atomic live mutation derivation
  version       '1'
  databaseHooks true}
 {name          sdk
  description   SDK generation: publishes a typed package of the stored definitions while the database is open
  version       '1'
  databaseHooks true}
 {name          skills
  description   Agent skills generation: publishes skills and reference files for the stored definitions while the database is open
  version       '1'
  databaseHooks true}]

C exports: stardust_db_close, stardust_db_retain, stardust_db_release

options

This record supplies options for open. The zero value selects every default.

Create

Creates a missing file. false refuses it with not_found.

  • Type: *bool
  • Default: true
  • Absent: nil

Clear

Discards all existing database contents after acquiring the exclusive file lock. Use true only to start an empty database.

  • Type: bool
  • Default: false

PinMemory

Locks the mapped database pages in RAM to prevent paging to disk. This also applies when the mapping grows. Opening or growing the mapping fails if the operating system refuses the memory lock.

  • Type: bool
  • Default: false

PageSize

Storage page size in bytes for a new database file. 0 selects the operating system page size. A negative value causes invalid_argument.

  • Type: int64
  • Unit: Bytes

LockTimeout

Waits for the lock of another process. 0 fails at once. A positive wait rounds up to whole milliseconds.

  • Type: time.Duration
  • Unit: Host duration (100 ns ticks at the ABI)
  • Range: Tick range
  • Default: 0
  • Absent: A negative duration

InitialMapBytes

Zero selects the library default.

  • Type: int64
  • Unit: Bytes

CommitBatch

Batch window for background commits nobody waits on. Write calls return once durable and never wait for it; concurrent writes share a sync regardless. Zero selects the library default and a negative duration causes invalid_argument.

Plugins

The plugins to enable, by name, each mapped to its load settings ({} for its defaults). Only named plugins are enabled.

  • Type: map[string]any
  • Absent: nil

MemoryBudgetBytes

The most bytes of working memory the database's queries, caches and initial bulk build hold together. Zero selects an eighth of physical memory, at least 256 MiB. Query ordering, distinct and grouping use temporary sorted runs when records do not fit in memory. Collected aggregate inputs and windows read bounded runs. A minimum workspace, indivisible value or requested output document that cannot fit reports out_of_memory. Small pages let callers read large results. Returned documents use caller-owned memory after transfer. Pages that the caller keeps and binding-side all_pages collections are outside this budget. An initial bulk build reports out_of_memory if a patch or its minimum workspace cannot fit, and publishes nothing. Operating-system file cache and the process baseline are outside this budget. A negative value causes invalid_argument.

  • Type: int64
  • Unit: Bytes