Skip to content

Keybindings ​

db.keybindings.get returns read-only snapshots for keybindings. 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 keybindings in a regular array.

ts
return db.keybindings.get
  .all()
  .map(item => ({
    ruleset: item.RulesetName,
    action: item.Action,
    key: item.KeyCombination,
  }))

toArray ​

Returns all matching keybindings in a regular array.

ts
return db.keybindings.get
  .toArray()
  .map(item => ({
    ruleset: item.RulesetName,
    action: item.Action,
    key: item.KeyCombination,
  }))

first ​

Returns the first matching keybinding, or undefined.

ts
return db.keybindings.get
  .first()?.KeyCombination

count ​

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

ts
return db.keybindings.get
  .count()

limit ​

Limits how many keybindings elements are accessed.

ts
return db.keybindings.get
  .limit(1)
  .map(item => ({
    ruleset: item.RulesetName,
    action: item.Action,
    key: item.KeyCombination,
  }))

sortedBy ​

Sorts keybindings by a database field.

ts
return db.keybindings.get
  .sortedBy('Action')
  .map(item => ({
    ruleset: item.RulesetName,
    action: item.Action,
    key: item.KeyCombination,
  }))

autoEdit ​

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

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

commit ​

Saves the pending changes.

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

rollback ​

Discards the pending changes.

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

write.delete ​

Deletes every matching keybinding in one transaction.

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

write.update ​

Applies a typed patch to every matching keybinding.

ts
return db.keybindings.get
  .limit(1)
  .write.update({ KeyCombination: 'Z' })

byAction ​

Finds keybindings where action matches the supplied value. You can chain more filters on the result.

ts
return db.keybindings.get
  .byAction(1)
  .map(item => ({
    ruleset: item.RulesetName,
    action: item.Action,
    key: item.KeyCombination,
  }))

byId ​

Finds keybindings where ID matches the supplied value. You can chain more filters on the result.

ts
return db.keybindings.get
  .byId('bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb')
  .map(item => ({
    ruleset: item.RulesetName,
    action: item.Action,
    key: item.KeyCombination,
  }))

byRulesetName ​

Finds keybindings where ruleset name matches the supplied value. You can chain more filters on the result.

ts
return db.keybindings.get
  .byRulesetName('osu')
  .map(item => ({
    ruleset: item.RulesetName,
    action: item.Action,
    key: item.KeyCombination,
  }))

byVariant ​

Finds keybindings where variant matches the supplied value. You can chain more filters on the result.

ts
return db.keybindings.get
  .byVariant(0)
  .map(item => ({
    ruleset: item.RulesetName,
    action: item.Action,
    key: item.KeyCombination,
  }))

Released under the MIT License.