Fix missing docs

This commit is contained in:
gwenn 2020-05-17 11:21:10 +02:00 committed by Thom Chiovoloni
parent 8a08dff115
commit 76fc22c653
14 changed files with 87 additions and 8 deletions

View File

@ -6,33 +6,55 @@ use crate::ffi;
use crate::{Connection, Result}; use crate::{Connection, Result};
/// Database Connection Configuration Options /// Database Connection Configuration Options
/// See [Database Connection Configuration Options](https://sqlite.org/c3ref/c_dbconfig_enable_fkey.html) for details.
#[repr(i32)] #[repr(i32)]
#[allow(non_snake_case, non_camel_case_types)] #[allow(non_snake_case, non_camel_case_types)]
#[non_exhaustive] #[non_exhaustive]
pub enum DbConfig { pub enum DbConfig {
//SQLITE_DBCONFIG_MAINDBNAME = 1000, /* const char* */ //SQLITE_DBCONFIG_MAINDBNAME = 1000, /* const char* */
//SQLITE_DBCONFIG_LOOKASIDE = 1001, /* void* int int */ //SQLITE_DBCONFIG_LOOKASIDE = 1001, /* void* int int */
/// Enable or disable the enforcement of foreign key constraints.
SQLITE_DBCONFIG_ENABLE_FKEY = 1002, SQLITE_DBCONFIG_ENABLE_FKEY = 1002,
/// Enable or disable triggers.
SQLITE_DBCONFIG_ENABLE_TRIGGER = 1003, SQLITE_DBCONFIG_ENABLE_TRIGGER = 1003,
/// Enable or disable the fts3_tokenizer() function which is part of the
/// FTS3 full-text search engine extension.
SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER = 1004, // 3.12.0 SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER = 1004, // 3.12.0
//SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION = 1005, //SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION = 1005,
/// In WAL mode, enable or disable the checkpoint operation before closing
/// the connection.
SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE = 1006, // 3.16.2 SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE = 1006, // 3.16.2
SQLITE_DBCONFIG_ENABLE_QPSG = 1007, // 3.20.0 /// Activates or deactivates the query planner stability guarantee (QPSG).
SQLITE_DBCONFIG_TRIGGER_EQP = 1008, // 3.22.0 SQLITE_DBCONFIG_ENABLE_QPSG = 1007, // 3.20.0
/// Includes or excludes output for any operations performed by trigger
/// programs from the output of EXPLAIN QUERY PLAN commands.
SQLITE_DBCONFIG_TRIGGER_EQP = 1008, // 3.22.0
//SQLITE_DBCONFIG_RESET_DATABASE = 1009, //SQLITE_DBCONFIG_RESET_DATABASE = 1009,
/// Activates or deactivates the "defensive" flag for a database connection.
SQLITE_DBCONFIG_DEFENSIVE = 1010, // 3.26.0 SQLITE_DBCONFIG_DEFENSIVE = 1010, // 3.26.0
/// Activates or deactivates the "writable_schema" flag.
#[cfg(feature = "modern_sqlite")] #[cfg(feature = "modern_sqlite")]
SQLITE_DBCONFIG_WRITABLE_SCHEMA = 1011, // 3.28.0 SQLITE_DBCONFIG_WRITABLE_SCHEMA = 1011, // 3.28.0
/// Activates or deactivates the legacy behavior of the ALTER TABLE RENAME
/// command.
#[cfg(feature = "modern_sqlite")] #[cfg(feature = "modern_sqlite")]
SQLITE_DBCONFIG_LEGACY_ALTER_TABLE = 1012, // 3.29 SQLITE_DBCONFIG_LEGACY_ALTER_TABLE = 1012, // 3.29
/// Activates or deactivates the legacy double-quoted string literal
/// misfeature for DML statements only.
#[cfg(feature = "modern_sqlite")] #[cfg(feature = "modern_sqlite")]
SQLITE_DBCONFIG_DQS_DML = 1013, // 3.29.0 SQLITE_DBCONFIG_DQS_DML = 1013, // 3.29.0
/// Activates or deactivates the legacy double-quoted string literal
/// misfeature for DDL statements.
#[cfg(feature = "modern_sqlite")] #[cfg(feature = "modern_sqlite")]
SQLITE_DBCONFIG_DQS_DDL = 1014, // 3.29.0 SQLITE_DBCONFIG_DQS_DDL = 1014, // 3.29.0
/// Enable or disable views.
#[cfg(feature = "modern_sqlite")] #[cfg(feature = "modern_sqlite")]
SQLITE_DBCONFIG_ENABLE_VIEW = 1015, // 3.30.0 SQLITE_DBCONFIG_ENABLE_VIEW = 1015, // 3.30.0
/// Activates or deactivates the legacy file format flag.
#[cfg(feature = "modern_sqlite")] #[cfg(feature = "modern_sqlite")]
SQLITE_DBCONFIG_LEGACY_FILE_FORMAT = 1016, // 3.31.0 SQLITE_DBCONFIG_LEGACY_FILE_FORMAT = 1016, // 3.31.0
/// Tells SQLite to assume that database schemas (the contents of the
/// sqlite_master tables) are untainted by malicious content.
#[cfg(feature = "modern_sqlite")] #[cfg(feature = "modern_sqlite")]
SQLITE_DBCONFIG_TRUSTED_SCHEMA = 1017, // 3.31.0 SQLITE_DBCONFIG_TRUSTED_SCHEMA = 1017, // 3.31.0
} }

View File

@ -94,6 +94,7 @@ pub enum Error {
#[allow(dead_code)] #[allow(dead_code)]
ModuleError(String), ModuleError(String),
/// An unwinding panic occurs in an UDF (user-defined function).
#[cfg(feature = "functions")] #[cfg(feature = "functions")]
UnwindingPanic, UnwindingPanic,

View File

@ -267,17 +267,26 @@ where
} }
bitflags::bitflags! { bitflags::bitflags! {
#[doc = "Function Flags."] /// Function Flags.
#[doc = "See [sqlite3_create_function](https://sqlite.org/c3ref/create_function.html) for details."] /// See [sqlite3_create_function](https://sqlite.org/c3ref/create_function.html)
/// and [Function Flags](https://sqlite.org/c3ref/c_deterministic.html) for details.
#[repr(C)] #[repr(C)]
pub struct FunctionFlags: ::std::os::raw::c_int { pub struct FunctionFlags: ::std::os::raw::c_int {
/// Specifies UTF-8 as the text encoding this SQL function prefers for its parameters.
const SQLITE_UTF8 = ffi::SQLITE_UTF8; const SQLITE_UTF8 = ffi::SQLITE_UTF8;
/// Specifies UTF-16 using little-endian byte order as the text encoding this SQL function prefers for its parameters.
const SQLITE_UTF16LE = ffi::SQLITE_UTF16LE; const SQLITE_UTF16LE = ffi::SQLITE_UTF16LE;
/// Specifies UTF-16 using big-endian byte order as the text encoding this SQL function prefers for its parameters.
const SQLITE_UTF16BE = ffi::SQLITE_UTF16BE; const SQLITE_UTF16BE = ffi::SQLITE_UTF16BE;
/// Specifies UTF-16 using native byte order as the text encoding this SQL function prefers for its parameters.
const SQLITE_UTF16 = ffi::SQLITE_UTF16; const SQLITE_UTF16 = ffi::SQLITE_UTF16;
/// Means that the function always gives the same output when the input parameters are the same.
const SQLITE_DETERMINISTIC = ffi::SQLITE_DETERMINISTIC; const SQLITE_DETERMINISTIC = ffi::SQLITE_DETERMINISTIC;
/// Means that the function may only be invoked from top-level SQL.
const SQLITE_DIRECTONLY = 0x0000_0008_0000; // 3.30.0 const SQLITE_DIRECTONLY = 0x0000_0008_0000; // 3.30.0
/// Indicates to SQLite that a function may call `sqlite3_value_subtype()` to inspect the sub-types of its arguments.
const SQLITE_SUBTYPE = 0x0000_0010_0000; // 3.30.0 const SQLITE_SUBTYPE = 0x0000_0010_0000; // 3.30.0
/// Means that the function is unlikely to cause problems even if misused.
const SQLITE_INNOCUOUS = 0x0000_0020_0000; // 3.31.0 const SQLITE_INNOCUOUS = 0x0000_0020_0000; // 3.31.0
} }
} }

View File

@ -14,9 +14,13 @@ use crate::{Connection, InnerConnection};
#[repr(i32)] #[repr(i32)]
#[non_exhaustive] #[non_exhaustive]
pub enum Action { pub enum Action {
/// Unsupported / unexpected action
UNKNOWN = -1, UNKNOWN = -1,
/// DELETE command
SQLITE_DELETE = ffi::SQLITE_DELETE, SQLITE_DELETE = ffi::SQLITE_DELETE,
/// INSERT command
SQLITE_INSERT = ffi::SQLITE_INSERT, SQLITE_INSERT = ffi::SQLITE_INSERT,
/// UPDATE command
SQLITE_UPDATE = ffi::SQLITE_UPDATE, SQLITE_UPDATE = ffi::SQLITE_UPDATE,
} }

View File

@ -53,7 +53,7 @@
//! Ok(()) //! Ok(())
//! } //! }
//! ``` //! ```
#![allow(unknown_lints)] #![warn(missing_docs)]
pub use libsqlite3_sys as ffi; pub use libsqlite3_sys as ffi;
@ -806,19 +806,32 @@ impl fmt::Debug for Connection {
} }
bitflags::bitflags! { bitflags::bitflags! {
#[doc = "Flags for opening SQLite database connections."] /// Flags for opening SQLite database connections.
#[doc = "See [sqlite3_open_v2](http://www.sqlite.org/c3ref/open.html) for details."] /// See [sqlite3_open_v2](http://www.sqlite.org/c3ref/open.html) for details.
#[repr(C)] #[repr(C)]
pub struct OpenFlags: ::std::os::raw::c_int { pub struct OpenFlags: ::std::os::raw::c_int {
/// The database is opened in read-only mode.
/// If the database does not already exist, an error is returned.
const SQLITE_OPEN_READ_ONLY = ffi::SQLITE_OPEN_READONLY; const SQLITE_OPEN_READ_ONLY = ffi::SQLITE_OPEN_READONLY;
/// The database is opened for reading and writing if possible,
/// or reading only if the file is write protected by the operating system.
/// In either case the database must already exist, otherwise an error is returned.
const SQLITE_OPEN_READ_WRITE = ffi::SQLITE_OPEN_READWRITE; const SQLITE_OPEN_READ_WRITE = ffi::SQLITE_OPEN_READWRITE;
/// The database is created if it does not already exist
const SQLITE_OPEN_CREATE = ffi::SQLITE_OPEN_CREATE; const SQLITE_OPEN_CREATE = ffi::SQLITE_OPEN_CREATE;
/// The filename can be interpreted as a URI if this flag is set.
const SQLITE_OPEN_URI = 0x0000_0040; const SQLITE_OPEN_URI = 0x0000_0040;
/// The database will be opened as an in-memory database.
const SQLITE_OPEN_MEMORY = 0x0000_0080; const SQLITE_OPEN_MEMORY = 0x0000_0080;
/// The new database connection will use the "multi-thread" threading mode.
const SQLITE_OPEN_NO_MUTEX = ffi::SQLITE_OPEN_NOMUTEX; const SQLITE_OPEN_NO_MUTEX = ffi::SQLITE_OPEN_NOMUTEX;
/// The new database connection will use the "serialized" threading mode.
const SQLITE_OPEN_FULL_MUTEX = ffi::SQLITE_OPEN_FULLMUTEX; const SQLITE_OPEN_FULL_MUTEX = ffi::SQLITE_OPEN_FULLMUTEX;
/// The database is opened shared cache enabled.
const SQLITE_OPEN_SHARED_CACHE = 0x0002_0000; const SQLITE_OPEN_SHARED_CACHE = 0x0002_0000;
/// The database is opened shared cache disabled.
const SQLITE_OPEN_PRIVATE_CACHE = 0x0004_0000; const SQLITE_OPEN_PRIVATE_CACHE = 0x0004_0000;
/// The database filename is not allowed to be a symbolic link.
const SQLITE_OPEN_NOFOLLOW = 0x0100_0000; const SQLITE_OPEN_NOFOLLOW = 0x0100_0000;
} }
} }

View File

@ -35,6 +35,8 @@ impl<'stmt> Rows<'stmt> {
Ok((*self).get()) Ok((*self).get())
} }
/// Map over this `Rows`, converting it to a [`Map`], which
/// implements `FallibleIterator`.
pub fn map<F, B>(self, f: F) -> Map<'stmt, F> pub fn map<F, B>(self, f: F) -> Map<'stmt, F>
where where
F: FnMut(&Row<'_>) -> Result<B>, F: FnMut(&Row<'_>) -> Result<B>,

View File

@ -6,8 +6,14 @@ use std::ops::Deref;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[non_exhaustive] #[non_exhaustive]
pub enum TransactionBehavior { pub enum TransactionBehavior {
/// DEFERRED means that the transaction does not actually start until the
/// database is first accessed.
Deferred, Deferred,
/// IMMEDIATE cause the database connection to start a new write
/// immediately, without waiting for a writes statement.
Immediate, Immediate,
/// EXCLUSIVE prevents other database connections from reading the database
/// while the transaction is underway.
Exclusive, Exclusive,
} }

View File

@ -86,6 +86,7 @@ pub type FromSqlResult<T> = Result<T, FromSqlError>;
/// fetching values as i64 and then doing the interpretation themselves or by /// fetching values as i64 and then doing the interpretation themselves or by
/// defining a newtype and implementing `FromSql`/`ToSql` for it. /// defining a newtype and implementing `FromSql`/`ToSql` for it.
pub trait FromSql: Sized { pub trait FromSql: Sized {
/// Converts SQLite value into Rust value.
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self>; fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self>;
} }

View File

@ -82,12 +82,19 @@ mod value_ref;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct Null; pub struct Null;
/// SQLite data types.
/// See [Fundamental Datatypes](https://sqlite.org/c3ref/c_blob.html).
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum Type { pub enum Type {
/// NULL
Null, Null,
/// 64-bit signed integer
Integer, Integer,
/// 64-bit IEEE floating point number
Real, Real,
/// String
Text, Text,
/// BLOB
Blob, Blob,
} }

View File

@ -87,6 +87,7 @@ impl ToSql for ToSqlOutput<'_> {
/// A trait for types that can be converted into SQLite values. /// A trait for types that can be converted into SQLite values.
pub trait ToSql { pub trait ToSql {
/// Converts Rust value to SQLite value
fn to_sql(&self) -> Result<ToSqlOutput<'_>>; fn to_sql(&self) -> Result<ToSqlOutput<'_>>;
} }

View File

@ -109,6 +109,7 @@ where
} }
impl Value { impl Value {
/// Returns SQLite fundamental datatype.
pub fn data_type(&self) -> Type { pub fn data_type(&self) -> Type {
match *self { match *self {
Value::Null => Type::Null, Value::Null => Type::Null,

View File

@ -20,6 +20,7 @@ pub enum ValueRef<'a> {
} }
impl ValueRef<'_> { impl ValueRef<'_> {
/// Returns SQLite fundamental datatype.
pub fn data_type(&self) -> Type { pub fn data_type(&self) -> Type {
match *self { match *self {
ValueRef::Null => Type::Null, ValueRef::Null => Type::Null,

View File

@ -46,6 +46,7 @@ pub(crate) unsafe extern "C" fn free_array(p: *mut c_void) {
let _: Array = Rc::from_raw(p as *const Vec<Value>); let _: Array = Rc::from_raw(p as *const Vec<Value>);
} }
/// Array parameter / pointer
pub type Array = Rc<Vec<Value>>; pub type Array = Rc<Vec<Value>>;
impl ToSql for Array { impl ToSql for Array {

View File

@ -205,7 +205,9 @@ impl VTabConnection {
/// ///
/// (See [SQLite doc](https://sqlite.org/c3ref/vtab.html)) /// (See [SQLite doc](https://sqlite.org/c3ref/vtab.html))
pub unsafe trait VTab: Sized { pub unsafe trait VTab: Sized {
/// Client data passed to `Connection::create_module`.
type Aux; type Aux;
/// Specific cursor implementation
type Cursor: VTabCursor; type Cursor: VTabCursor;
/// Establish a new connection to an existing virtual table. /// Establish a new connection to an existing virtual table.
@ -256,8 +258,9 @@ pub trait CreateVTab: VTab {
} }
/// `feature = "vtab"` Index constraint operator. /// `feature = "vtab"` Index constraint operator.
/// See [Virtual Table Constraint Operator Codes](https://sqlite.org/c3ref/c_index_constraint_eq.html) for details.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[allow(non_snake_case, non_camel_case_types)] #[allow(non_snake_case, non_camel_case_types, missing_docs)]
#[non_exhaustive] #[non_exhaustive]
pub enum IndexConstraintOp { pub enum IndexConstraintOp {
SQLITE_INDEX_CONSTRAINT_EQ, SQLITE_INDEX_CONSTRAINT_EQ,
@ -329,6 +332,7 @@ impl IndexInfo {
unsafe { (*self.0).nOrderBy as usize } unsafe { (*self.0).nOrderBy as usize }
} }
/// Information about what parameters to pass to `VTabCursor.filter`.
pub fn constraint_usage(&mut self, constraint_idx: usize) -> IndexConstraintUsage<'_> { pub fn constraint_usage(&mut self, constraint_idx: usize) -> IndexConstraintUsage<'_> {
let constraint_usages = unsafe { let constraint_usages = unsafe {
slice::from_raw_parts_mut((*self.0).aConstraintUsage, (*self.0).nConstraint as usize) slice::from_raw_parts_mut((*self.0).aConstraintUsage, (*self.0).nConstraint as usize)
@ -495,6 +499,7 @@ pub unsafe trait VTabCursor: Sized {
pub struct Context(*mut ffi::sqlite3_context); pub struct Context(*mut ffi::sqlite3_context);
impl Context { impl Context {
/// Set current cell value
pub fn set_result<T: ToSql>(&mut self, value: &T) -> Result<()> { pub fn set_result<T: ToSql>(&mut self, value: &T) -> Result<()> {
let t = value.to_sql()?; let t = value.to_sql()?;
unsafe { set_result(self.0, &t) }; unsafe { set_result(self.0, &t) };
@ -511,14 +516,17 @@ pub struct Values<'a> {
} }
impl Values<'_> { impl Values<'_> {
/// Returns the number of values.
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.args.len() self.args.len()
} }
/// Returns `true` if there is no value.
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.args.is_empty() self.args.is_empty()
} }
/// Returns value at `idx`
pub fn get<T: FromSql>(&self, idx: usize) -> Result<T> { pub fn get<T: FromSql>(&self, idx: usize) -> Result<T> {
let arg = self.args[idx]; let arg = self.args[idx];
let value = unsafe { ValueRef::from_value(arg) }; let value = unsafe { ValueRef::from_value(arg) };
@ -558,6 +566,7 @@ impl Values<'_> {
} }
} }
/// Turns `Values` into an iterator.
pub fn iter(&self) -> ValueIter<'_> { pub fn iter(&self) -> ValueIter<'_> {
ValueIter { ValueIter {
iter: self.args.iter(), iter: self.args.iter(),
@ -574,6 +583,7 @@ impl<'a> IntoIterator for &'a Values<'a> {
} }
} }
/// `Values` iterator.
pub struct ValueIter<'a> { pub struct ValueIter<'a> {
iter: slice::Iter<'a, *mut ffi::sqlite3_value>, iter: slice::Iter<'a, *mut ffi::sqlite3_value>,
} }