Compare commits
2 Commits
e5a56888ad
...
50fa9b5179
| Author | SHA1 | Date | |
|---|---|---|---|
|
50fa9b5179
|
|||
|
46bbd4859e
|
@@ -53,6 +53,7 @@ Project or files:
|
|||||||
│ ├── barrel
|
│ ├── barrel
|
||||||
│ ├── bonsaidb
|
│ ├── bonsaidb
|
||||||
│ ├── diesel
|
│ ├── diesel
|
||||||
|
│ ├── duckdb-demo
|
||||||
│ ├── gluesql
|
│ ├── gluesql
|
||||||
│ ├── mysqlsvr
|
│ ├── mysqlsvr
|
||||||
│ ├── persy
|
│ ├── persy
|
||||||
@@ -292,6 +293,6 @@ Project or files:
|
|||||||
├── vec.rs
|
├── vec.rs
|
||||||
└── while.rs
|
└── while.rs
|
||||||
|
|
||||||
261 directories, 40 files
|
262 directories, 40 files
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
1442
__database/duckdb-demo/Cargo.lock
generated
Normal file
1442
__database/duckdb-demo/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
10
__database/duckdb-demo/Cargo.toml
Normal file
10
__database/duckdb-demo/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "duckdb-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
duckdb = { version = "0.10", features = ["bundled"] }
|
||||||
|
|
||||||
55
__database/duckdb-demo/src/main.rs
Normal file
55
__database/duckdb-demo/src/main.rs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
use duckdb::{params, Connection, Result};
|
||||||
|
|
||||||
|
use duckdb::arrow::record_batch::RecordBatch;
|
||||||
|
use duckdb::arrow::util::pretty::print_batches;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Person {
|
||||||
|
id: i32,
|
||||||
|
name: String,
|
||||||
|
data: Option<Vec<u8>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
let conn = Connection::open_in_memory()?;
|
||||||
|
|
||||||
|
conn.execute_batch(
|
||||||
|
r"CREATE SEQUENCE seq;
|
||||||
|
CREATE TABLE person (
|
||||||
|
id INTEGER PRIMARY KEY DEFAULT NEXTVAL('seq'),
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
data BLOB
|
||||||
|
);
|
||||||
|
")?;
|
||||||
|
|
||||||
|
let me = Person {
|
||||||
|
id: 0,
|
||||||
|
name: "Steven".to_string(),
|
||||||
|
data: None,
|
||||||
|
};
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO person (name, data) VALUES (?, ?)",
|
||||||
|
params![me.name, me.data],
|
||||||
|
)?;
|
||||||
|
|
||||||
|
// query table by rows
|
||||||
|
let mut stmt = conn.prepare("SELECT id, name, data FROM person")?;
|
||||||
|
let person_iter = stmt.query_map([], |row| {
|
||||||
|
Ok(Person {
|
||||||
|
id: row.get(0)?,
|
||||||
|
name: row.get(1)?,
|
||||||
|
data: row.get(2)?,
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
for person in person_iter {
|
||||||
|
let p = person.unwrap();
|
||||||
|
println!("ID: {}", p.id);
|
||||||
|
println!("Found person {:?}", p);
|
||||||
|
}
|
||||||
|
|
||||||
|
// query table by arrow
|
||||||
|
let rbs: Vec<RecordBatch> = stmt.query_arrow([])?.collect();
|
||||||
|
print_batches(&rbs).unwrap();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user