File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/sqlite3.cpython-310.pyc
Back
o ;j�: � @ sx d Z zddlZdZW n ey dZY nw dd� Zddd�Zdd d �Zdd� Zdd d�Zddd�Z dd� Z dd� ZdS )a� Management of SQLite3 databases =============================== .. versionadded:: 2016.3.0 :depends: - SQLite3 Python Module :configuration: See :py:mod:`salt.modules.sqlite3` for setup instructions The sqlite3 module is used to create and manage sqlite3 databases and execute queries Here is an example of creating a table using sql statements: .. code-block:: yaml users: sqlite3.table_present: - db: /var/www/data/app.sqlite - schema: CREATE TABLE `users` (`username` TEXT COLLATE NOCASE UNIQUE NOT NULL, `password` BLOB NOT NULL, `salt` BLOB NOT NULL, `last_login` INT) Here is an example of creating a table using yaml/jinja instead of sql: .. code-block:: yaml users: sqlite3.table_present: - db: /var/www/app.sqlite - schema: - email TEXT COLLATE NOCASE UNIQUE NOT NULL - firstname TEXT NOT NULL - lastname TEXT NOT NULL - company TEXT NOT NULL - password BLOB NOT NULL - salt BLOB NOT NULL Here is an example of making sure a table is absent: .. code-block:: yaml badservers: sqlite3.table_absent: - db: /var/www/data/users.sqlite Sometimes you would to have specific data in tables to be used by other services Here is an example of making sure rows with specific data exist: .. code-block:: yaml user_john_doe_xyz: sqlite3.row_present: - db: /var/www/app.sqlite - table: users - where_sql: email='john.doe@companyxyz.com' - data: email: john.doe@companyxyz.com lastname: doe firstname: john company: companyxyz.com password: abcdef012934125 salt: abcdef012934125 - require: - sqlite3: users Here is an example of removing a row from a table: .. code-block:: yaml user_john_doe_abc: sqlite3.row_absent: - db: /var/www/app.sqlite - table: users - where_sql: email="john.doe@companyabc.com" - require: - sqlite3: users Note that there is no explicit state to perform random queries, however, this can be approximated with sqlite3's module functions and module.run: .. code-block:: yaml zone-delete: module.run: - name: sqlite3.modify - db: {{ db }} - sql: "DELETE FROM records WHERE id > {{ count[0] }} AND domain_id = {{ domain_id }}" - watch: - sqlite3: zone-insert-12 � NTFc C s t rdS dS )z6 Only load if the sqlite3 module is available T)FzUnable to import sqlite3)�HAS_SQLITE3� r r �G/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/sqlite3.py�__virtual__g s r c C s� | i ddd�}d}z�z�t j|t jd�}t|_d}|du r(t|d| d | �}nt|d| d | |�}t|�dkrCd|d <