-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
201 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: build and deploy docs | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
paths: | ||
- "docs/**" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Rust | ||
uses: ATiltedTree/setup-rust@v1 | ||
with: | ||
rust-version: stable | ||
components: clippy | ||
|
||
- name: Install mdbook | ||
run: | | ||
cargo install mdbook | ||
- name: Build mdBook | ||
working-directory: docs | ||
run: | | ||
mdbook build | ||
- name: Copy CNAME file | ||
working-directory: docs | ||
run: | | ||
cp CNAME ./book/ | ||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GH_TOKEN }} | ||
publish_dir: ./docs/book |
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 @@ | ||
docs.njord.rs |
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,14 @@ | ||
[book] | ||
title = "Njord - A lightweight ORM library in Rust" | ||
authors = ["Marcus Cvjeticanin"] | ||
description = "A lightweight ORM library in Rust with strong-typed SQL DSL and sequence API." | ||
language = "en" | ||
git-repository-url = "https://github.com/mjovanc/njord" | ||
git-repository-icon = "fa-github" | ||
copy-fonts = true | ||
edit-url-template = "https://github.com/mjovanc/njord/tree/docs/src/{path}" | ||
cname = "njord.rs" | ||
input-404 = "not-found.md" | ||
|
||
[build] | ||
target-dir = "book" |
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,19 @@ | ||
fn main() { | ||
println!("Welcome to the Official Njord Documentation!"); | ||
println!("============================================"); | ||
println!(" ~. "); | ||
println!(" Ya...___|__..ab. . . "); | ||
println!(" Y88b \\88b \\88b ( ) "); | ||
println!(" Y88b :88b :88b `.oo' "); | ||
println!(" :888 |888 |888 ( (`-' "); | ||
println!(" .---. d88P ;88P ;88P `.`. "); | ||
println!(" / .-._) d8P-\"\"\"|\"\"\"'-Y8P `.`. "); | ||
println!(" ( (`._) .-. .-. |.-. .-. .-. ) ) "); | ||
println!(" \\ `---( O )( O )( O )( O )( O )-' / "); | ||
println!(" `. `-' `-' `-' `-' `-' .' "); | ||
println!(" `---------------------------' "); | ||
println!("============================================"); | ||
println!(" ~~~~~~~~~~~~~~~~~~~~~~ "); | ||
println!(" ~~~~~~~~~~~~~~~~~~~~~~~~~~ "); | ||
println!(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "); | ||
} |
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,14 @@ | ||
# Njord | ||
|
||
Njord is a lightweight ORM library for Rust with strong-typed SQL DSL and sequence API. | ||
|
||
## Database support | ||
|
||
| Database | Support | Description | | ||
|------------|------------|------------------------| | ||
| SQLite | ✅ | Currently supported | | ||
| PostgreSQL | ❌ | Not supported | | ||
| MySQL | ❌ | Not supported | | ||
| MariaDB | ❌ | Not supported | | ||
| Oracle | ❌ | Not supported | | ||
| MSSQL | ❌ | Not supported | |
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 @@ | ||
# Summary | ||
|
||
[Introduction](README.md) | ||
|
||
- [Getting started](getting-started.md) | ||
- [SQlite](sqlite/sqlite.md) | ||
- [Setup connection](sqlite/connection.md) | ||
- [Initialize database with tables](sqlite/initialize-database-with-tables.md) | ||
- [Insert](sqlite/insert.md) | ||
- [Drop](sqlite/drop.md) | ||
- [Select](sqlite/select.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,14 @@ | ||
# Getting started | ||
|
||
To install Njord into your Rust project we need to include the dependencies: | ||
|
||
**Cargo.toml** | ||
```toml | ||
[dependencies] | ||
|
||
# The core APIs, including the Table trait. Always | ||
# required when using njord. The "derive" feature is only required when | ||
# using #[derive(Table)] to make njord work with structs | ||
# and enums defined in your crate. | ||
njord = { version = "0.1.0", features = ["derive"] } | ||
``` |
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 @@ | ||
# 404 - Not found! |
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,13 @@ | ||
# Setup connection | ||
|
||
First thing you need to do is to setup a connection is: | ||
|
||
```rust | ||
let conn = sqlite::open("my_database.db"); | ||
``` | ||
|
||
We can also use a in-memory database: | ||
|
||
```rust | ||
let conn = sqlite::open_in_memory("my_database.db"); | ||
``` |
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,16 @@ | ||
# Define tables | ||
|
||
To define a table we use derive with the `Table` (provided by Njord) and `Default` procedural macro. Then we create a simple struct with a given name. The name of the struct will be the table name in the database: | ||
|
||
```rust | ||
#[derive(Table, Default)] | ||
struct Posts { | ||
title: String, | ||
description: String, | ||
} | ||
|
||
#[derive(Table, Default)] | ||
struct Categories { | ||
name: String, | ||
} | ||
``` |
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,7 @@ | ||
# Drop table | ||
|
||
To drop a table, it is a simple as: | ||
|
||
```rust | ||
sqlite::drop_table(conn, &Posts::default()); | ||
``` |
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,20 @@ | ||
# Initialize database with tables | ||
|
||
First thing we need to do before we do any `insert`, `select` etc is to initialize the database with the defined tables. To initialize the database we need to box the struct and call `default()` and save it to a variable: | ||
|
||
```rust | ||
let posts_table = Box::<Posts>::default(); | ||
let categories_table = Box::<Categories>::default(); | ||
``` | ||
|
||
Now we add them to a tables vector: | ||
|
||
```rust | ||
let mut tables: Vec<Box<dyn Table>> = vec![posts_table, categories_table]; | ||
``` | ||
|
||
Lastly, we call the `init()` function to setup the tables from the tables vector, such as: | ||
|
||
```rust | ||
sqlite::init(conn, tables); | ||
``` |
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,16 @@ | ||
# Insert data to table | ||
|
||
To insert data, we need to initialize our Posts struct that we created with values for each field: | ||
|
||
```rust | ||
let table_row: Posts = Posts { | ||
title: "A post title".to_string(), | ||
description: "Some description for for a post".to_string(), | ||
}; | ||
``` | ||
|
||
We insert the row by passing a connection and a reference to the table_row: | ||
|
||
```rust | ||
sqlite::insert(conn, &table_row); | ||
``` |
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,13 @@ | ||
# Select | ||
|
||
Docs are coming soon... | ||
|
||
## WHERE | ||
|
||
## ORDER BY | ||
|
||
## GROUP BY | ||
|
||
## LIMIT | ||
|
||
## OFFSET |
Empty file.