depends: |
|
---|---|
configuration: | See |
Beryllium 新版功能.
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:
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:
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:
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:
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:
user_john_doe_abc: sqlite3.row_absent: - db: /var/www/app.sqlite - table: users - where_sql: email="john.doe@companyabc.com" - require: - sqlite3: users
salt.states.sqlite3.
row_absent
(name, db, table, where_sql, where_args=None)¶Makes sure the specified row is absent in db. If multiple rows match where_sql, then the state will fail.
salt.states.sqlite3.
row_present
(name, db, table, data, where_sql, where_args=None, update=False)¶Checks to make sure the given row exists. If row exists and update is True then row will be updated with data. Otherwise it will leave existing row unmodified and check it against data. If the existing data doesn't match data_check the state will fail. If the row doesn't exist then it will insert data into the table. If more than one row matches, then the state will fail.
salt.states.sqlite3.
table_absent
(name, db)¶Make sure the specified table does not exist
salt.states.sqlite3.
table_present
(name, db, schema, force=False)¶Make sure the specified table exists with the specified schema