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

Refactor/remove async #212

Merged
merged 4 commits into from
Aug 7, 2024
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
78 changes: 32 additions & 46 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,58 @@ description = "SQL as a Function for Rust"
license = "Apache-2.0"
repository = "https://github.com/KipData/KipSQL"
readme = "README.md"
keywords = ["async", "sql", "sqlite", "database", "mysql"]
keywords = ["sql", "sqlite", "database", "mysql"]
categories = ["development-tools", "database"]
default-run = "fnck_sql"

[[bin]]
name = "fnck_sql"
path = "src/bin/server.rs"
required-features = ["net"]

[lib]
doctest = false

[features]
default = ["marcos", "net"]
default = ["marcos"]
marcos = []
net = ["dep:pgwire", "dep:async-trait", "dep:env_logger", "dep:log"]

[[bench]]
name = "query_bench"
path = "benchmarks/query_benchmark.rs"
harness = false

[dependencies]
ahash = { version = "0.8.11" }
async-lock = { version = "3.3.0" }
async-trait = { version = "0.1.77", optional = true }
bincode = { version = "1.3.3" }
bytes = { version = "1.5.0" }
chrono = { version = "0.4.26" }
clap = { version = "4.5.2" }
comfy-table = { version = "7.1.0" }
csv = { version = "1.3.0" }
dirs = { version = "5.0.1" }
env_logger = { version = "0.11.3", optional = true }
futures = { version = "0.3.30" }
futures-async-stream = { version = "0.2.11" }
integer-encoding = { version = "3.0.4" }
itertools = { version = "0.12.1" }
kip_db = { version = "0.1.2-alpha.26.fix1" }
lazy_static = { version = "1.4.0" }
log = { version = "0.4.21", optional = true }
ordered-float = { version = "4.2.0" }
paste = { version = "1.0.14" }
petgraph = { version = "0.6.4" }
pgwire = { version = "0.19.2", optional = true }
rand = { version = "0.9.0-alpha.0" }
regex = { version = "1.10.3" }
rust_decimal = { version = "1.34.3" }
serde = { version = "1.0.197", features = ["derive", "rc"] }
siphasher = { version = "1.0.0", features = ["serde"] }
sqlparser = { version = "0.34.0", features = ["serde"] }
ahash = { version = "0.8" }
bincode = { version = "1" }
bytes = { version = "1" }
chrono = { version = "0.4" }
clap = { version = "4" }
comfy-table = { version = "7" }
csv = { version = "1" }
dirs = { version = "5" }
integer-encoding = { version = "3" }
itertools = { version = "0.12" }
lazy_static = { version = "1" }
ordered-float = { version = "4" }
paste = { version = "1" }
parking_lot = { version = "0.12", features = ["arc_lock"] }
petgraph = { version = "0.6" }
rand = { version = "0.9.0-alpha" }
regex = { version = "1" }
rocksdb = { git = "https://github.com/rust-rocksdb/rust-rocksdb", rev = "1cf906dc4087f06631820f13855e6b27bd21b972" }
rust_decimal = { version = "1" }
serde = { version = "1", features = ["derive", "rc"] }
siphasher = { version = "1", features = ["serde"] }
sqlparser = { version = "0.34", features = ["serde"] }
strum_macros = { version = "0.26.2" }
thiserror = { version = "1.0.58" }
tokio = { version = "1.36.0", features = ["full"] }
tracing = { version = "0.1.40" }
thiserror = { version = "1" }
tracing = { version = "0.1" }
typetag = { version = "0.2" }

[dev-dependencies]
cargo-tarpaulin = { version = "0.27.1" }
criterion = { version = "0.5.1", features = ["async_tokio", "html_reports"] }
indicatif = { version = "0.17.8" }
rand_distr = { version = "0.4.3" }
tempfile = { version = "3.10.1" }
tokio-test = { version = "0.4.3" }
cargo-tarpaulin = { version = "0.27" }
criterion = { version = "0.5", features = ["async_tokio", "html_reports"] }
indicatif = { version = "0.17" }
rand_distr = { version = "0.4" }
tempfile = { version = "3.10" }
# Benchmark
sqlite = { version = "0.34.0" }
sqlite = { version = "0.34" }

[target.'cfg(unix)'.dev-dependencies]
pprof = { version = "0.13", features = ["flamegraph", "criterion"] }
Expand Down
38 changes: 6 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Built by @KipData
<p align="center">
<a href="https://github.com/KipData/KipSQL/actions/workflows/ci.yml"><img src="https://github.com/KipData/KipSQL/actions/workflows/ci.yml/badge.svg" alt="CI"></img></a>
<a href="https://crates.io/crates/fnck_sql/"><img src="https://img.shields.io/crates/v/fnck_sql.svg"></a>
<a href="https://hub.docker.com/r/kould23333/fncksql"><img src="https://img.shields.io/badge/Docker-fncksql-2496ED?logo=docker"></a>
</p>
<p align="center">
<a href="https://github.com/KipData/KipSQL" target="_blank">
Expand All @@ -41,52 +40,29 @@ FnckSQL individual developers independently implemented LSM KV-based SQL DBMS ou
Welcome to our WebSite, Power By FnckSQL: **http://www.kipdata.site/**

### Quick Started
Tips: Install rust toolchain first.
Tips: Install rust toolchain and llvm first.

Clone the repository
``` shell
git clone https://github.com/KipData/FnckSQL.git
```
![start](./static/images/start.gif)
then use `psql` to enter sql
![pg](./static/images/pg.gif)

Using FnckSQL in code
```rust
let fnck_sql = DataBaseBuilder::path("./data")
.build()
.await?;
let tuples = fnck_sql.run("select * from t1").await?;
.build()?;
let tuples = fnck_sql.run("select * from t1")?;
```
Storage Support:
- KipDB
- RocksDB

### Docker
#### Pull Image
```shell
docker pull kould23333/fncksql:latest
```
#### Build From Source
~~~shell
git clone https://github.com/KipData/FnckSQL.git
cd FnckSQL
docker build -t kould23333/fncksql:latest .
~~~

#### Run
We installed the `psql` tool in the image for easy debug.

You can use `psql -h 127.0.0.1 -p 5432` to do this.

~~~shell
docker run -d \
--name=fncksql \
-p 5432:5432 \
--restart=always \
-v fncksql-data:/fnck_sql/fncksql_data \
-v /etc/localtime:/etc/localtime:ro \
kould23333/fncksql:latest
~~~

### Features
- ORM Mapping: `features = ["marcos"]`
```rust
Expand Down Expand Up @@ -123,15 +99,13 @@ function!(TestFunction::test(LogicalType::Integer, LogicalType::Integer) -> Logi

let fnck_sql = DataBaseBuilder::path("./data")
.register_function(TestFunction::new())
.build()
.await?;
.build()?;
```
- Optimizer
- RBO
- CBO based on RBO(Physical Selection)
- Execute
- Volcano
- Codegen on LuaJIT: `features = ["codegen_execute"]`
- MVCC Transaction
- Optimistic
- Field options
Expand Down
17 changes: 6 additions & 11 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,20 @@ implement_from_tuple!(
);

#[cfg(feature = "marcos")]
#[tokio::main]
async fn main() -> Result<(), DatabaseError> {
let database = DataBaseBuilder::path("./hello_world").build().await?;
fn main() -> Result<(), DatabaseError> {
let database = DataBaseBuilder::path("./hello_world").build()?;

let _ = database
.run("create table if not exists my_struct (c1 int primary key, c2 int)")
.await?;
let _ = database
.run("insert into my_struct values(0, 0), (1, 1)")
.await?;
let (schema, tuples) = database.run("select * from my_struct").await?;
let _ = database.run("create table if not exists my_struct (c1 int primary key, c2 int)")?;
let _ = database.run("insert into my_struct values(0, 0), (1, 1)")?;
let (schema, tuples) = database.run("select * from my_struct")?;
let tuples = tuples
.into_iter()
.map(|tuple| MyStruct::from((&schema, tuple)))
.collect_vec();

println!("{:#?}", tuples);

let _ = database.run("drop table my_struct").await?;
let _ = database.run("drop table my_struct")?;

Ok(())
}
21 changes: 9 additions & 12 deletions examples/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
use fnck_sql::db::DataBaseBuilder;
use fnck_sql::errors::DatabaseError;

#[tokio::main]
async fn main() -> Result<(), DatabaseError> {
let database = DataBaseBuilder::path("./transaction").build().await?;
let mut tx_1 = database.new_transaction().await?;
fn main() -> Result<(), DatabaseError> {
let database = DataBaseBuilder::path("./transaction").build()?;
let mut tx_1 = database.new_transaction()?;

let _ = tx_1
.run("create table if not exists t1 (c1 int primary key, c2 int)")
.await?;
let _ = tx_1.run("insert into t1 values(0, 0), (1, 1)").await?;
let _ = tx_1.run("create table if not exists t1 (c1 int primary key, c2 int)")?;
let _ = tx_1.run("insert into t1 values(0, 0), (1, 1)")?;

assert!(database.run("select * from t1").await.is_err());
assert!(database.run("select * from t1").is_err());

tx_1.commit().await?;
tx_1.commit()?;

assert!(database.run("select * from t1").await.is_ok());
assert!(database.run("select * from t1").is_ok());

let _ = database.run("drop table t1").await?;
let _ = database.run("drop table t1")?;

Ok(())
}
Loading
Loading