saveToDB


Description:

public void saveToDB (Database db, FileBase? new_values = null, bool sync = true)

Save filebase object to SQLite database.

ID Semantics

  • id = 0: New file (inserts into database, sets this.id to new ID)
  • id > 0: Existing file (updates database record)
  • id < 0: Fake file (skips database operations, returns early)

Update Modes

  • If new_values is provided and this.id > 0: Uses updateOld to only update changed fields
  • Otherwise: Performs insert (id = 0) or full update (id > 0)

Best Practices

  • Set sync = false when saving multiple items to avoid frequent disk writes
  • Fake files (id < 0) automatically skip database operations
  • New files (id = 0) are automatically inserted and assigned an ID

Parameters:

db

The database instance to save to

new_values

Optional new values object. If provided and this.id > 0, uses updateOld to only update changed fields. Otherwise performs insert or full update.

sync

If true, backup the in-memory database to disk immediately. Set to false when saving multiple items to avoid frequent disk writes.