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.
return db.files.get
.all()
.map(item => ({
hash: item.Hash,
}))toArray
Returns all matching files in a regular array.
return db.files.get
.toArray()
.map(item => ({
hash: item.Hash,
}))first
Returns the first matching file, or undefined.
return db.files.get
.first()?.Hashcount
Counts all matching files, even when a limit is set.
return db.files.get
.count()limit
Limits how many files elements are accessed.
return db.files.get
.limit(1)
.map(item => ({
hash: item.Hash,
}))sortedBy
Sorts files by a database field.
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.
const session = db.files.get
.limit(1)
.autoEdit()
const length = session.length
session.rollback()
return lengthcommit
Saves the pending changes.
const session = db.files.get
.limit(1)
.autoEdit()
const length = session.length
session.commit()
return lengthrollback
Discards the pending changes.
const session = db.files.get
.limit(1)
.autoEdit()
const length = session.length
session.rollback()
return lengthwrite.delete
Deletes every matching file in one transaction.
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.
return db.files.get
.byHash('a'.repeat(64))
.map(item => ({
hash: item.Hash,
}))