-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SQLite database open recipe (#464)
- Loading branch information
Showing
8 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# SQLite | ||
|
||
{{#include sqlite/initialization.md}} | ||
|
||
{{#include ../links.md}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
[linking]: https://github.com/jgallagher/rusqlite#user-content-notes-on-building-rusqlite-and-libsqlite3-sys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters