Schema Builder
A fluent API for conveniently constructing Apache Arrow schemas.
Overview
SchemaBuilder lets you define schemas intuitively through method chaining, eliminating the need to manually create Arrow Field objects and combine them into a Schema.
Basic Usage
use dbx_core::SchemaBuilder;
use arrow::datatypes::DataType;
let schema = SchemaBuilder::new()
.column("id", DataType::Int64, false)
.column("name", DataType::Utf8, true)
.build();
Database Integration (Table Creation)
Use the create_table_with_builder method on Database for convenient table creation.
use dbx_core::Database;
let db = Database::open_in_memory()?;
// Create table with schema builder
db.create_table_with_builder("users", |builder| {
builder
.id("id")
.text("name").not_null()
.text("email").not_null()
.int32("age")
})?;
Convenience Methods
Shorthand methods are provided for common data types:
id(name):Int64, NOT NULLtext(name):Utf8, nullable by defaultint32(name):Int32, nullable by defaultint64(name):Int64, nullable by defaultfloat64(name):Float64, nullable by defaultboolean(name):Boolean, nullable by defaulttimestamp(name):Timestamp(Millisecond), nullable by default
let schema = SchemaBuilder::new()
.id("user_id")
.text("username")
.int32("age")
.boolean("is_active")
.timestamp("created_at")
.build();
Nullability Control
Columns created with convenience methods are nullable by default (except id). Use not_null() or nullable() to change this.
let schema = SchemaBuilder::new()
.text("email").not_null() // required field
.text("nickname").nullable() // optional field
.build();
Next Steps
- Query Builder — Fluent API for querying data
- SQL Reference — Standard SQL usage in DBX