Skip to content

Commit

Permalink
Prepare publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
kawasin73 committed Aug 5, 2023
1 parent f641774 commit 6337a45
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 3 deletions.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: actions
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- run: cargo fmt --all -- --check
- run: cargo clippy --all-targets --all-features -- -D warnings
- run: cargo build
- run: cargo test
88 changes: 86 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,92 @@
# prsqlite - Pure Rust SQLite

Pure Rust implementation of SQLite.
Pure Rust implementation of [SQLite](https://www.sqlite.org/index.html).

This is WIP & a hobby project.
This is WIP and my hobby project.

* Compatible with database file generated by sqlite3
* prsqlite uses the SQLite
[Database File Format](https://www.sqlite.org/fileformat2.html#b_tree_pages).
* Support SQL syntax which SQLite supports
* See [SQL As Understood By SQLite](https://www.sqlite.org/lang.html).
* Some syntax is not implemented yet.
* Zero dependency
* except dev-dependency.
* While developing as WIP, prsqlite is using `anyhow` for development
velocity. It will be replaced with a proprietary errors in the future.
* Validating file format
* prsqlite does not trust the file is valid unlike sqlite3 and validates pages
in the file while parsing.
* `trust-file` feature will be added to disable the file validation.
* No unsafe
* Will be supported in the future.

NOTE: This repository is not stable yet. I may force-push commit tree even on
the main branch.

## Usage

See [integration_test.rs](./tests/integration_test.rs) for what prsqlite
supports.

`prsqlite::Connection::open()` is the entrypoint interface for library users.

```rs
use std::path::Path;

use prsqlite::Connection;
use prsqlite::NextRow;
use prsqlite::Value;

let mut conn = Connection::open(Path::new("path/to/sqlite.db")).unwrap();
let mut stmt = conn.prepare("SELECT * FROM example WHERE col = 1;").unwrap();
let mut rows = stmt.execute().unwrap();

let row = rows.next().unwrap().unwrap();
let columns = row.parse().unwrap();
assert_eq!(columns.get(0), &Value::Integer(1));
drop(row);

// `Rows::next()` may return `NextRow::Skip` due to the limitation of Rust
// borrow checker (See the doc comment of `NextRow`). Just call `Rows::next()`
// again in that case. Hopefully this will be resolved when prsqlite use virtual
// database engine to execute queries.
assert!(matches!(rows.next().unwrap(), NextRow::Skip));

assert!(rows.next().unwrap().is_none());
```

prsqlite provides REPL command.

```bash
$ git clone https://github.com/kawasin73/prsqlite.git

$ cd ./prsqlite

$ sqlite3 tmp/sqlite.db
sqlite> CREATE TABLE example(col1, col2 integer);
sqlite> CREATE INDEX i_example ON example(col2);
sqlite> INSERT INTO example(col1, col2) values(null, 1);
sqlite> INSERT INTO example(col1, col2) values(10, 2);
sqlite> INSERT INTO example(col1, col2) values(1.1, 3);
sqlite> INSERT INTO example(col1, col2) values('Hello prsqlite!', 4);
sqlite> INSERT INTO example(col1, col2) values(X'707273716c697465', 5);
sqlite> .quit

$ cargo build && ./target/debug/prsqlite tmp/sqlite.db
prsqlite> SELECT * FROM sqlite_schema;
table|example|example|2|CREATE TABLE example(col1, col2 integer)
index|i_example|example|3|CREATE INDEX i_example ON example(col2)
prsqlite> SELECT * FROM example;
|1
10|2
1.1|3
Hello prsqlite!|4
prsqlite|5
prsqlite> SELECT col1 FROM example WHERE col2 == 4;
Hello prsqlite!
prsqlite> .quit
```

## Contributing

Expand Down
7 changes: 6 additions & 1 deletion docs/contributing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# How to Contribute

We would love to accept your patches and contributions to this project.
This project is now WIP and not accepting any PR until this hits the first
milestone. Sorry. If you want to develop sqlite with Rust, feel free to fork
this repository!

After this hits the first milestone, we would love to accept your patches and
contributions to this project.

## Before you begin

Expand Down

0 comments on commit 6337a45

Please sign in to comment.