ttafsir.sqlite_utils.create (1.4.0) — module

Create a table in an SQLite database.

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 allows you to create a table in an SQLite database.

It uses the sqlite-utils Python library to handle the operations.

The database file is created if it doesn't exist.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Create a simple table
- name: Create a table
  ttafsir.sqlite_utils.create:
    db_path: /path/to/database.db
    table: cats
    columns:
      name: str
      breed: str
      weight: float
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Create a table with additional configurations
- name: Create a table with a primary key and default values
  ttafsir.sqlite_utils.create:
    db_path: /path/to/database.db
    table: cats
    columns:
      id: int
      name: str
      breed: str
      weight: float
    pk: id
    defaults:
      breed: "Unknown"

Inputs

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

table:
    description:
    - Name of the table to create.
    required: true
    type: str

ignore:
    default: false
    description:
    - If set to True and table already exists, silently ignores the operation.
    type: bool

columns:
    description:
    - Columns for the table in the form of a dictionary, where the key is the column name
      and the value is the column type.
    - Supported Python types are "str", "float", "int", "bool", "bytes", "datetime", "date",
      and "time".
    required: true
    type: dict

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

replace:
    default: false
    description:
    - If set to True, drops the table if it exists and creates a new one.
    type: bool

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

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

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

if_not_exists:
    default: false
    description:
    - If set to True, does nothing if table already exists.
    type: bool