Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite open database recipe #464

Merged
merged 1 commit into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions ci/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,11 @@ resize
resized
RESTful
ReverseDependencies
rusqlite
rustaceans
rustc
RwLock
SQLite
SecureRandom
SemVer
Semver
Expand All @@ -263,6 +265,7 @@ SetLoggerError
SigningKey
SocketAddrV
StatusCode
sqlite
stderr
stdin
Stdout
Expand Down
2 changes: 2 additions & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions src/database.md
Original file line number Diff line number Diff line change
@@ -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}}
5 changes: 5 additions & 0 deletions src/database/sqlite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SQLite

{{#include sqlite/initialization.md}}

{{#include ../links.md}}
41 changes: 41 additions & 0 deletions src/database/sqlite/initialization.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
4 changes: 4 additions & 0 deletions src/links.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down