ttafsir.sqlite_utils.insert (1.4.0) — module

Insert a single record into an SQLite database table.

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

This module inserts a single record into an SQLite database table.

It uses the sqlite-utils Python library to perform the operation.

The table will be created or modified as necessary based on the parameters provided.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Insert a single record into the 'cats' table
- name: Insert record into cats table
  ttafs:
    db_path: /path/to/database.db
    table: cats
    records:
      name: 'Whiskers'
      breed: 'Tabby'
      age: 5
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Insert record into cats table
  ttafs:
    db_path: /path/to/database.db
    table: cats
    records:
      - name: 'Whiskers'
        breed: 'Tabby'
        age: 5
      - name: 'Fluffy'
        breed: 'Persian'
        age: 3

Inputs

    
pk:
    description:
    - Specifies which column should be the primary key when creating the table.
    type: str

alter:
    default: false
    description:
    - If set, missing columns will be added automatically.
    type: bool

table:
    description:
    - Name of the table to insert data into.
    required: true
    type: str

ignore:
    default: false
    description:
    - If a record with the same primary key already exists, the insertion will be ignored.
    type: bool

columns:
    description:
    - Dictionary overriding the detected types used for columns.
    type: dict

db_path:
    description:
    - Path to the SQLite database.
    - Ensure the database file is accessible and writable.
    required: true
    type: str

hash_id:
    description:
    - Name of a column to create and use as a primary key, with its value derived as a
      SHA1 hash of other column values in the record.
    type: str

records:
    description:
    - The record to insert into the table, represented as a dictionary.
    required: true
    type: raw

replace:
    default: false
    description:
    - If a record with the same primary key already exists, it will be replaced.
    type: bool

defaults:
    description:
    - Specifies default values for specific columns.
    type: dict

extracts:
    description:
    - List of columns to extract to other tables, or a dictionary that maps column names
      to other table names.
    type: raw

not_null:
    description:
    - Specifies columns that should be NOT NULL.
    elements: raw
    type: list

conversions:
    description:
    - Dictionary specifying SQL conversion functions to apply to data during insertion.
    type: dict

column_order:
    description:
    - Specifies a full or partial column order to use when creating the table.
    elements: raw
    type: list