diff --git a/Cargo.toml b/Cargo.toml index 698435d9..bc5c1658 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ rayon = "1.0" regex = "1.0" reqwest = "0.9" ring = "0.13.0-alpha" +rusqlite = "0.14" same-file = "1.0" select = "0.4" semver = "0.9" diff --git a/ci/dictionary.txt b/ci/dictionary.txt index 6ecb1bf3..a80bc906 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -247,9 +247,11 @@ resize resized RESTful ReverseDependencies +rusqlite rustaceans rustc RwLock +SQLite SecureRandom SemVer Semver @@ -263,6 +265,7 @@ SetLoggerError SigningKey SocketAddrV StatusCode +sqlite stderr stdin Stdout diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 94ff9d8d..cae9496b 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -18,6 +18,8 @@ - [Encryption](cryptography/encryption.md) - [Data Structures](data_structures.md) - [Bitfield](data_structures/bitfield.md) +- [Database](database.md) + - [SQLite](database/sqlite.md) - [Date and Time](datetime.md) - [Duration and Calculation](datetime/duration.md) - [Parsing and Displaying](datetime/parse.md) diff --git a/src/database.md b/src/database.md new file mode 100644 index 00000000..0dcadbaa --- /dev/null +++ b/src/database.md @@ -0,0 +1,11 @@ +# Database + +## SQLite + +| Recipe | Crates | Categories | +|--------|--------|------------| +| [Create a SQLite database][ex-sqlite-initialization] | [![rusqlite-badge]][rusqlite] | [![cat-database-badge]][cat-database] | + +[ex-sqlite-initialization]: database/sqlite.html#create-a-sqlite-database + +{{#include links.md}} diff --git a/src/database/sqlite.md b/src/database/sqlite.md new file mode 100644 index 00000000..f90f4b21 --- /dev/null +++ b/src/database/sqlite.md @@ -0,0 +1,5 @@ +# SQLite + +{{#include sqlite/initialization.md}} + +{{#include ../links.md}} diff --git a/src/database/sqlite/initialization.md b/src/database/sqlite/initialization.md new file mode 100644 index 00000000..1fcae346 --- /dev/null +++ b/src/database/sqlite/initialization.md @@ -0,0 +1,41 @@ +## Create a SQLite database + +[![rusqlite-badge]][rusqlite] [![cat-database-badge]][cat-database] + +Use the `rusqlite` crate to open SQLite databases. See +[crate][documentation] for compiling on Windows. + +[`Connection::open`] will create the database if it doesn't already exist. + +```rust,no_run +extern crate rusqlite; + +use rusqlite::{Connection, Result}; + +fn main() -> Result<()> { + let conn = Connection::open("cats.db")?; + + conn.execute( + "create table if not exists cat_colors ( + id integer primary key, + name text not null + )", + &[], + )?; + conn.execute( + "create table if not exists cats ( + id integer primary key, + name text not null, + date_of_birth datetime, + color_id integer not null references cat_colors(id) + )", + &[], + )?; + + Ok(()) +} +``` + +[`Connection::open`]: https://docs.rs/rusqlite/*/rusqlite/struct.Connection.html#method.open + +[documentation]: https://github.com/jgallagher/rusqlite#user-content-notes-on-building-rusqlite-and-libsqlite3-sys diff --git a/src/intro.md b/src/intro.md index 63169f93..7e7f916b 100644 --- a/src/intro.md +++ b/src/intro.md @@ -28,6 +28,8 @@ community. It needs and welcomes help. For details see {{#include data_structures.md}} +{{#include database.md}} + {{#include datetime.md}} {{#include development_tools.md}} diff --git a/src/links.md b/src/links.md index 57834b83..ba6f8bf9 100644 --- a/src/links.md +++ b/src/links.md @@ -17,6 +17,8 @@ Keep lines sorted. [cat-config]: https://crates.io/categories/config [cat-cryptography-badge]: https://badge-cache.kominick.com/badge/cryptography--x.svg?style=social [cat-cryptography]: https://crates.io/categories/cryptography +[cat-database-badge]: https://badge-cache.kominick.com/badge/database--x.svg?style=social +[cat-database]: https://crates.io/categories/database [cat-date-and-time-badge]: https://badge-cache.kominick.com/badge/date_and_time--x.svg?style=social [cat-date-and-time]: https://crates.io/categories/date-and-time [cat-debugging-badge]: https://badge-cache.kominick.com/badge/debugging--x.svg?style=social @@ -106,6 +108,8 @@ Keep lines sorted. [reqwest]: https://docs.rs/reqwest/ [ring-badge]: https://badge-cache.kominick.com/crates/v/ring.svg?label=ring [ring]: https://briansmith.org/rustdoc/ring/ +[rusqlite-badge]: https://badge-cache.kominick.com/crates/v/rusqlite.svg?label=rusqlite +[rusqlite]: https://crates.io/crates/rusqlite/ [same_file-badge]: https://badge-cache.kominick.com/crates/v/same_file.svg?label=same_file [same_file]: https://docs.rs/same-file/ [select-badge]: https://badge-cache.kominick.com/crates/v/select.svg?label=select