Skip to content

Commit

Permalink
Adding docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mjovanc committed Jun 19, 2024
2 parents 8ba6165 + 21ca3d3 commit d4e40c6
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/docs.yml
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
1 change: 1 addition & 0 deletions docs/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs.njord.rs
14 changes: 14 additions & 0 deletions docs/book.toml
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"
19 changes: 19 additions & 0 deletions docs/main.rs
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!(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ");
}
14 changes: 14 additions & 0 deletions docs/src/README.md
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 |
11 changes: 11 additions & 0 deletions docs/src/SUMMARY.md
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)
14 changes: 14 additions & 0 deletions docs/src/getting-started.md
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"] }
```
1 change: 1 addition & 0 deletions docs/src/not-found.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 404 - Not found!
13 changes: 13 additions & 0 deletions docs/src/sqlite/connection.md
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");
```
16 changes: 16 additions & 0 deletions docs/src/sqlite/define-tables.md
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,
}
```
7 changes: 7 additions & 0 deletions docs/src/sqlite/drop.md
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());
```
20 changes: 20 additions & 0 deletions docs/src/sqlite/initialize-database-with-tables.md
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);
```
16 changes: 16 additions & 0 deletions docs/src/sqlite/insert.md
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);
```
13 changes: 13 additions & 0 deletions docs/src/sqlite/select.md
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 added docs/src/sqlite/sqlite.md
Empty file.

0 comments on commit d4e40c6

Please sign in to comment.