Available on crate feature
__sqlite-shared only.Expand description
Typed access to SQLite pragmas.
A pragma is declared as a type implementing Pragma, with ReadPragma when it returns rows and WritePragma when it can be assigned an argument. Its Scope decides whether it is used per database or per connection, and the caller picks the Rust type each row decodes into.
§Per-schema pragmas
A PerSchema pragma applies to one database and is read and written through SchemaPragma, where a None schema selects main.
use diesel::sqlite::pragma::{PerSchema, Pragma, ReadPragma, SchemaPragma, WritePragma};
struct UserVersion;
impl Pragma for UserVersion {
const NAME: &'static str = "user_version";
type Scope = PerSchema;
}
impl ReadPragma for UserVersion {
type SqlType = Integer;
}
impl WritePragma for UserVersion {
type Argument<'a> = i32;
}
let conn = &mut SqliteConnection::establish(":memory:").unwrap();
UserVersion::set(7, None, conn)?;
assert_eq!(7, UserVersion::get::<i32>(None, conn)?);§Per-connection pragmas
A PerConnection pragma applies to the whole connection and is read and written through ConnectionPragma, which takes no schema.
use diesel::sqlite::pragma::{
ConnectionPragma, PerConnection, Pragma, ReadPragma, WritePragma,
};
struct ForeignKeys;
impl Pragma for ForeignKeys {
const NAME: &'static str = "foreign_keys";
type Scope = PerConnection;
}
impl ReadPragma for ForeignKeys {
type SqlType = Bool;
}
impl WritePragma for ForeignKeys {
type Argument<'a> = bool;
}
let conn = &mut SqliteConnection::establish(":memory:").unwrap();
ForeignKeys::set(true, conn)?;
assert!(ForeignKeys::get::<bool>(conn)?);Structs§
- Auto
Vacuum PRAGMA auto_vacuum, read and set as anAutoVacuumMode.- Freelist
Count PRAGMA freelist_count, the unused pages on a database’s freelist, read as ani64.- Incremental
Vacuum PRAGMA incremental_vacuum, shrinking a database by releasing freelist pages without the full rewriteVACUUMperforms.- Page
Count PRAGMA page_count, the total number of pages in a database, read as ani64.- Pragma
Keyword - A keyword written unquoted, such as
WALorNORMAL. - Pragma
Text - Text written as a single-quoted SQL string with embedded quotes doubled, such as
'UTF-16le'.
Enums§
- PerConnection
- A connection-wide pragma, whose schema qualifier SQLite ignores.
- PerSchema
- A pragma that applies to one database,
mainor an attached one.
Traits§
- Connection
Pragma - Reads and writes a
PerConnectionpragma. - Pragma
- A pragma, named by
NAMEand scoped byScope. - Pragma
Argument - A value written into a pragma statement, which takes no bind parameters.
- Pragma
Scope - Whether a pragma targets one database or the whole connection.
- Read
Pragma - A pragma that returns rows when queried.
- Schema
Pragma - Reads and writes a
PerSchemapragma, where aNoneschema selectsmain. - Write
Pragma - A pragma that can be assigned an
Argument.