ttafsir.sqlite_utils.sqlite (1.4.0) — lookup

Query SQLite databases using the sqlite-utils package

Authors: Tafsir Thiam (@ttafsir)

Install collection

Install with ansible-galaxy collection install ttafsir.sqlite_utils:==1.4.0


Add to requirements.yml

  collections:
    - name: ttafsir.sqlite_utils
      version: 1.4.0

Description

The sqlite lookup plugin allows querying SQLite databases using the sqlite-utils package.

Features include filtering rows, selecting specific columns, ordering results, and counting rows.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Fetch all rows from SQLite
  debug:
    msg: "{{ lookup('ttafsir.sqlite_utils.sqlite', table='emails', db_path='database.db') }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Fetch single column from SQLite
  debug:
    msg: "{{ lookup('ttafsir.sqlite_utils.sqlite', table='emails', db_path='database.db', select='email_id') }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Fetch two columns from SQLite
  debug:
    msg: "{{ lookup('ttafsir.sqlite_utils.sqlite', table='emails', db_path='database.db', select='email_id, subject') }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Fetch single row using a WHERE clause
  debug:
    msg: "{{ lookup('ttafsir.sqlite_utils.sqlite', table='emails', db_path='database.db', where='subject = :subject', where_args={'subject': 'Peek #4'}) }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Loop through all rows and display a specific column
  debug:
    msg: "{{ item.subject }}"
  loop: "{{ lookup('ttafsir.sqlite_utils.sqlite', table='emails', db_path='database.db') }}"

Inputs

    
count:
    description: Return count of rows instead of rows themselves.
    type: bool

limit:
    description: Limit the number of returned results.
    type: int

where:
    description: Optional WHERE clause.
    type: str

offset:
    description: Offset for returned results.
    type: int

select:
    description: Columns to select. Default is '*'.
    type: str

db_path:
    description:
    - Path to the SQLite database.
    - Defaults to the SQLITE_DB_PATH environment variable.
    type: str

order_by:
    description: Order results by specified column(s).
    type: str

table_name:
    description: Name of the table to query.
    required: true
    type: str

where_args:
    description: Optional arguments for the WHERE clause.
    type: raw