# Object Instance `luci.model.uci`

## Functions

Cursor:add (config, type) | Add an anonymous section.
Cursor:apply (rollback) | Applies UCI configuration changes.
Cursor:changes (config) | Get a table of saved but uncommitted changes.
Cursor:commit (config) | Commit saved changes.
Cursor:confirm () | Confirms UCI apply process.
Cursor:delete (config, section, option) | Deletes a section or an option.
Cursor:delete_all (config, type, comparator) | Delete all sections of a given type that match certain criteria.
Cursor:foreach (config, type, callback) | Call a function for every section of a certain type.
Cursor:get (config, section, option) | Get a section type or an option
Cursor:get_all (config, section) | Get all sections of a config or all values of a section.
Cursor:get_bool (config, section, option) | Get a boolean option and return it's value as true or false.
Cursor:get_confdir () | Get the configuration directory.
Cursor:get_first (config, type, option, default) | Get the given option from the first section with the given type.
Cursor:get_list (config, section, option) | Get an option or list and return values as table.
Cursor:get_savedir () | Get the directory for uncomitted changes.
Cursor:get_session_id () | Get the effective session ID.
Cursor:load (config) | Manually load a config.
Cursor:revert (config) | Revert saved but uncommitted changes.
Cursor:rollback () | Cancels UCI apply process.
Cursor:rollback_pending () | Checks whether a pending rollback is scheduled.
Cursor:save (config) | Saves changes made to a config to make them committable.
Cursor:section (config, type, name, values) | Create a new section and initialize it with data.
Cursor:set (config, section, option, value) | Set a value or create a named section.
Cursor:set_confdir (directory) | Set the configuration directory.
Cursor:set_list (config, section, option, value) | Set given values as list.
Cursor:set_savedir (directory) | Set the directory for uncommitted changes.
Cursor:set_session_id (id) | Set the effective session ID.
Cursor:substate () | Create a sub-state of this cursor.
Cursor:tset (config, section, values) | Updated the data of a section using data from a table.
Cursor:unload (config) | Discard changes made to a config.
cursor () | Create a new UCI-Cursor.
cursor_state () | Create a new Cursor initialized to the state directory.

## Functions

Cursor:add (config, type)
  Add an anonymous section.

  ### Parameters

  - config: UCI config
  - type: UCI section type

  ### Return value:

  Name of created section
Cursor:apply (rollback)
  Applies UCI configuration changes. If the rollback parameter is set to true, the apply function will invoke the rollback mechanism which causes the configuration to be automatically reverted if no confirm() call occurs within a certain timeout. The current default timeout is 30s and can be increased using the "luci.apply.timeout" uci configuration key.

  ### Parameters

  - rollback: Enable rollback mechanism

  ### Return value:

  Boolean whether operation succeeded
Cursor:changes (config)
  Get a table of saved but uncommitted changes.

  ### Parameters

  - config: UCI config

  ### Return value:

  Table of changes

  ### See also:

  - Cursor:save
Cursor:commit (config)
  Commit saved changes.

  ### Parameters

  - config: UCI config

  ### Return value:

  Boolean whether operation succeeded

  ### See also:

  - Cursor:revert
  - Cursor:save
Cursor:confirm ()
  Confirms UCI apply process. If a previous UCI apply with rollback has been invoked using apply(true), this function confirms the process and cancels the pending rollback timer. If no apply with rollback session is active, the function has no effect and returns with a "No data" error.

  ### Return value:

  Boolean whether operation succeeded
Cursor:delete (config, section, option)
  Deletes a section or an option.

  ### Parameters

  - config: UCI config
  - section: UCI section name
  - option: UCI option (optional)

  ### Return value:

  Boolean whether operation succeeded
Cursor:delete_all (config, type, comparator)
  Delete all sections of a given type that match certain criteria.

  ### Parameters

  - config: UCI config
  - type: UCI section type
  - comparator: Function that will be called for each section and returns a boolean whether to delete the current section (optional)
Cursor:foreach (config, type, callback)
  Call a function for every section of a certain type.

  ### Parameters

  - config: UCI config
  - type: UCI section type
  - callback: Function to be called

  ### Return value:

  Boolean whether operation succeeded
Cursor:get (config, section, option)
  Get a section type or an option

  ### Parameters

  - config: UCI config
  - section: UCI section name
  - option: UCI option (optional)

  ### Return value:

  UCI value
Cursor:get_all (config, section)
  Get all sections of a config or all values of a section.

  ### Parameters

  - config: UCI config
  - section: UCI section name (optional)

  ### Return value:

  Table of UCI sections or table of UCI values
Cursor:get_bool (config, section, option)
  Get a boolean option and return it's value as true or false.

  ### Parameters

  - config: UCI config
  - section: UCI section name
  - option: UCI option

  ### Return value:

  Boolean
Cursor:get_confdir ()
  Get the configuration directory.

  ### Return value:

  Configuration directory
Cursor:get_first (config, type, option, default)
  Get the given option from the first section with the given type.

  ### Parameters

  - config: UCI config
  - type: UCI section type
  - option: UCI option (optional)
  - default: Default value (optional)

  ### Return value:

  UCI value
Cursor:get_list (config, section, option)
  Get an option or list and return values as table.

  ### Parameters

  - config: UCI config
  - section: UCI section name
  - option: UCI option

  ### Return value:

  table. If the option was not found, you will simply get an empty table.
Cursor:get_savedir ()
  Get the directory for uncomitted changes.

  ### Return value:

  Save directory
Cursor:get_session_id ()
  Get the effective session ID.

  ### Return value:

  String containing the session ID
Cursor:load (config)
  Manually load a config.

  ### Parameters

  - config: UCI config

  ### Return value:

  Boolean whether operation succeeded

  ### See also:

  - Cursor:save
  - Cursor:unload
Cursor:revert (config)
  Revert saved but uncommitted changes.

  ### Parameters

  - config: UCI config

  ### Return value:

  Boolean whether operation succeeded

  ### See also:

  - Cursor:commit
  - Cursor:save
Cursor:rollback ()
  Cancels UCI apply process. If a previous UCI apply with rollback has been invoked using apply(true), this function cancels the process and rolls back the configuration to the pre-apply state. If no apply with rollback session is active, the function has no effect and returns with a "No data" error.

  ### Return value:

  Boolean whether operation succeeded
Cursor:rollback_pending ()
  Checks whether a pending rollback is scheduled. If a previous UCI apply with rollback has been invoked using apply(true), and has not been confirmed or rolled back yet, this function returns true and the remaining time until rollback in seconds. If no rollback is pending, the function returns false. On error, the function returns false and an additional string describing the error.

  ### Return values:

  1. Boolean whether rollback is pending
  2. Remaining time in seconds
Cursor:save (config)
  Saves changes made to a config to make them committable.

  ### Parameters

  - config: UCI config

  ### Return value:

  Boolean whether operation succeeded

  ### See also:

  - Cursor:load
  - Cursor:unload
Cursor:section (config, type, name, values)
  Create a new section and initialize it with data.

  ### Parameters

  - config: UCI config
  - type: UCI section type
  - name: UCI section name (optional)
  - values: Table of key - value pairs to initialize the section with

  ### Return value:

  Name of created section
Cursor:set (config, section, option, value)
  Set a value or create a named section. When invoked with three arguments `config`, `sectionname`, `sectiontype`, then a named section of the given type is created. When invoked with four arguments `config`, `sectionname`, `optionname` and `optionvalue` then the value of the specified option is set to the given value.

  ### Parameters

  - config: UCI config
  - section: UCI section name
  - option: UCI option or UCI section type
  - value: UCI value or nothing if you want to create a section

  ### Return value:

  Boolean whether operation succeeded
Cursor:set_confdir (directory)
  Set the configuration directory.

  ### Parameters

  - directory: UCI configuration directory

  ### Return value:

  Boolean whether operation succeeded
Cursor:set_list (config, section, option, value)
  Set given values as list. Setting a list option to an empty list has the same effect as deleting the option.

  ### Parameters

  - config: UCI config
  - section: UCI section name
  - option: UCI option
  - value: Value or table. Non-table values will be set as single item UCI list.

  ### Return value:

  Boolean whether operation succeeded
Cursor:set_savedir (directory)
  Set the directory for uncommitted changes.

  ### Parameters

  - directory: UCI changes directory

  ### Return value:

  Boolean whether operation succeeded
Cursor:set_session_id (id)
  Set the effective session ID.

  ### Parameters

  - id: String containing the session ID to set

  ### Return value:

  Boolean whether operation succeeded
Cursor:substate ()
  Create a sub-state of this cursor. The sub-state is tied to the parent cursor, means it the parent unloads or loads configs, the sub state will do so as well.

  ### Return value:

  UCI state cursor tied to the parent cursor
Cursor:tset (config, section, values)
  Updated the data of a section using data from a table.

  ### Parameters

  - config: UCI config
  - section: UCI section name (optional)
  - values: Table of key - value pairs to update the section with
Cursor:unload (config)
  Discard changes made to a config.

  ### Parameters

  - config: UCI config

  ### Return value:

  Boolean whether operation succeeded

  ### See also:

  - Cursor:load
  - Cursor:save
cursor ()
  Create a new UCI-Cursor.

  ### Return value:

  UCI-Cursor
cursor_state ()
  Create a new Cursor initialized to the state directory.

  ### Return value:

  UCI cursor