Skip to content

Files ​

db.files.get returns read-only snapshots for files. You can keep chaining filters or use normal array methods.

These examples use a small fixture that resets for every run. Your application still uses its own Realm database.

all ​

Returns all matching files in a regular array.

ts
return db.files.get
  .all()
  .map(item => ({
    hash: item.Hash,
  }))

toArray ​

Returns all matching files in a regular array.

ts
return db.files.get
  .toArray()
  .map(item => ({
    hash: item.Hash,
  }))

first ​

Returns the first matching file, or undefined.

ts
return db.files.get
  .first()?.Hash

count ​

Counts all matching files, even when a limit is set.

ts
return db.files.get
  .count()

limit ​

Limits how many files elements are accessed.

ts
return db.files.get
  .limit(1)
  .map(item => ({
    hash: item.Hash,
  }))

sortedBy ​

Sorts files by a database field.

ts
return db.files.get
  .sortedBy('Hash')
  .map(item => ({
    hash: item.Hash,
  }))

autoEdit ​

Starts an edit session that buffers changes to matching files. Commit or roll them back when you are done.

ts
const session = db.files.get
  .limit(1)
  .autoEdit()
const length = session.length
session.rollback()
return length

commit ​

Saves the pending changes.

ts
const session = db.files.get
  .limit(1)
  .autoEdit()
const length = session.length
session.commit()
return length

rollback ​

Discards the pending changes.

ts
const session = db.files.get
  .limit(1)
  .autoEdit()
const length = session.length
session.rollback()
return length

write.delete ​

Deletes every matching file in one transaction.

ts
return db.files.get
  .limit(1)
  .write.delete()

byHash ​

Finds files where hash matches the supplied value. You can chain more filters on the result.

ts
return db.files.get
  .byHash('a'.repeat(64))
  .map(item => ({
    hash: item.Hash,
  }))

Released under the MIT License.