-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathmod.rs
52 lines (51 loc) · 1.84 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! # Generate SQL statements from Arrow schemas
//!
//! This module provides a set of functions to generate SQL statements (i.e. DML) from Arrow schemas.
//!
//! The primary use case is for generating `CREATE TABLE`/`INSERT INTO` statements for SQL databases from Arrow schemas/values with given constraints.
//!
//! ## Example
//!
//! ### `CREATE TABLE` statement
//! ```rust
//! use std::sync::Arc;
//! use datafusion::arrow::datatypes::{DataType, Field, Schema};
//! use datafusion_table_providers::sql::arrow_sql_gen::statement::CreateTableBuilder;
//!
//! let schema = Arc::new(Schema::new(vec![
//! Field::new("id", DataType::Int32, false),
//! Field::new("name", DataType::Utf8, false),
//! Field::new("age", DataType::Int32, false),
//! ]));
//!
//! let sql = CreateTableBuilder::new(schema, "my_table").build_sqlite();
//!
//! assert_eq!(r#"CREATE TABLE IF NOT EXISTS "my_table" ( "id" integer NOT NULL, "name" text NOT NULL, "age" integer NOT NULL )"#, sql);
//! ```
//!
//! With primary key constraints:
//! ```rust
//! use std::sync::Arc;
//! use datafusion::arrow::datatypes::{DataType, Field, Schema};
//! use datafusion_table_providers::sql::arrow_sql_gen::statement::CreateTableBuilder;
//!
//! let schema = Arc::new(Schema::new(vec![
//! Field::new("id", DataType::Int32, false),
//! Field::new("name", DataType::Utf8, false),
//! Field::new("age", DataType::Int32, false),
//! ]));
//!
//! let sql = CreateTableBuilder::new(schema, "my_table")
//! .primary_keys(vec!["id"])
//! .build_sqlite();
//!
//! assert_eq!(r#"CREATE TABLE IF NOT EXISTS "my_table" ( "id" integer NOT NULL, "name" text NOT NULL, "age" integer NOT NULL, PRIMARY KEY ("id") )"#, sql);
//! ```
pub mod arrow;
#[cfg(feature = "mysql")]
pub mod mysql;
#[cfg(feature = "postgres")]
pub mod postgres;
#[cfg(feature = "sqlite")]
pub mod sqlite;
pub mod statement;