Database

Struct Database 

Source
pub struct Database { /* private fields */ }
Expand description

The main database object.

Implementations§

Source§

impl Database

Source

pub fn list_catalogs(&self) -> Result<Vec<CatalogInfo>>

Catalog 一覧を取得する。

Source

pub fn get_catalog(&self, name: &str) -> Result<CatalogInfo>

Catalog を取得する。

Source

pub fn list_namespaces(&self, catalog_name: &str) -> Result<Vec<NamespaceInfo>>

Namespace 一覧を取得する。

Source

pub fn get_namespace( &self, catalog_name: &str, namespace_name: &str, ) -> Result<NamespaceInfo>

Namespace を取得する。

Source

pub fn list_tables( &self, catalog_name: &str, namespace_name: &str, ) -> Result<Vec<TableInfo>>

テーブル一覧を取得する。

Source

pub fn list_tables_simple(&self) -> Result<Vec<TableInfo>>

デフォルト catalog/namespace のテーブル一覧を取得する。

Source

pub fn get_table_info( &self, catalog_name: &str, namespace_name: &str, table_name: &str, ) -> Result<TableInfo>

テーブル情報を取得する。

Source

pub fn get_table_info_simple(&self, table_name: &str) -> Result<TableInfo>

デフォルト catalog/namespace のテーブル情報を取得する。

Source

pub fn get_table_info_cached( &self, catalog_name: &str, namespace_name: &str, table_name: &str, ) -> Result<CachedTableInfo>

テーブル情報をキャッシュから取得する(キャッシュミス時は DB ルックアップ)。

パフォーマンス最適化のため、キャッシュを使用してテーブルメタデータを取得する。 DDL 操作(テーブル作成/削除など)が発生するとキャッシュは自動的に無効化される。

Source

pub fn list_indexes( &self, catalog_name: &str, namespace_name: &str, table_name: &str, ) -> Result<Vec<IndexInfo>>

インデックス一覧を取得する。

Source

pub fn list_indexes_simple(&self, table_name: &str) -> Result<Vec<IndexInfo>>

デフォルト catalog/namespace のインデックス一覧を取得する。

Source

pub fn get_index_info( &self, catalog_name: &str, namespace_name: &str, table_name: &str, index_name: &str, ) -> Result<IndexInfo>

インデックス情報を取得する。

Source

pub fn get_index_info_simple( &self, table_name: &str, index_name: &str, ) -> Result<IndexInfo>

デフォルト catalog/namespace のインデックス情報を取得する。

Source

pub fn create_catalog( &self, request: CreateCatalogRequest, ) -> Result<CatalogInfo>

Catalog を作成する。

§Examples
use alopex_embedded::{CreateCatalogRequest, Database};

let db = Database::new();
let catalog = db.create_catalog(CreateCatalogRequest::new("main")).unwrap();
assert_eq!(catalog.name, "main");
Source

pub fn delete_catalog(&self, name: &str, force: bool) -> Result<()>

Catalog を削除する。

Source

pub fn create_namespace( &self, request: CreateNamespaceRequest, ) -> Result<NamespaceInfo>

Namespace を作成する。

§Examples
use alopex_embedded::{CreateCatalogRequest, CreateNamespaceRequest, Database};

let db = Database::new();
db.create_catalog(CreateCatalogRequest::new("main")).unwrap();
let namespace = db
    .create_namespace(CreateNamespaceRequest::new("main", "analytics"))
    .unwrap();
assert_eq!(namespace.catalog_name, "main");
assert_eq!(namespace.name, "analytics");
Source

pub fn delete_namespace( &self, catalog_name: &str, namespace_name: &str, force: bool, ) -> Result<()>

Namespace を削除する。

Source

pub fn create_table(&self, request: CreateTableRequest) -> Result<TableInfo>

テーブルを作成する。

§Examples
use alopex_embedded::{
    ColumnDefinition, CreateCatalogRequest, CreateNamespaceRequest, CreateTableRequest,
    Database,
};
use alopex_sql::ast::ddl::DataType;

let db = Database::new();
db.create_catalog(CreateCatalogRequest::new("default")).unwrap();
db.create_namespace(CreateNamespaceRequest::new("default", "default"))
    .unwrap();

let schema = vec![ColumnDefinition::new("id", DataType::Integer)];
let table = db
    .create_table(CreateTableRequest::new("users").with_schema(schema))
    .unwrap();
assert_eq!(table.name, "users");
Source

pub fn create_table_simple( &self, name: &str, schema: Vec<ColumnDefinition>, ) -> Result<TableInfo>

デフォルト catalog/namespace のテーブルを作成する。

Source

pub fn delete_table( &self, catalog_name: &str, namespace_name: &str, table_name: &str, ) -> Result<()>

テーブルを削除する。

Source

pub fn delete_table_simple(&self, name: &str) -> Result<()>

デフォルト catalog/namespace のテーブルを削除する。

Source§

impl Database

Source

pub fn open_with_config(config: EmbeddedConfig) -> Result<Self>

構成付きでデータベースを開く(カラムナー機能を初期化)。

Source

pub fn storage_mode(&self) -> StorageMode

現在のカラムナーストレージモードを返す。

Source

pub fn write_columnar_segment( &self, table: &str, batch: RecordBatch, ) -> Result<u64>

カラムナーセグメントを書き込む。

Source

pub fn write_columnar_segment_with_config( &self, table: &str, batch: RecordBatch, config: SegmentConfigV2, ) -> Result<u64>

カラムナーセグメントを書き込む(構成上書き)。

Source

pub fn read_columnar_segment( &self, table: &str, segment_id: u64, columns: Option<&[&str]>, ) -> Result<Vec<RecordBatch>>

カラムナーセグメントを読み取る(カラム名指定オプション付き)。

Source

pub fn in_memory_usage(&self) -> Option<u64>

InMemory モード時のメモリ使用量を返す。Disk モードでは None。

Source

pub fn open_in_memory_with_limit(limit: usize) -> Result<Self>

メモリ上限付きでインメモリ DB を開く。

Source

pub fn resolve_table_id(&self, table: &str) -> Result<u32>

テーブル名から内部 ID を解決する。

Source

pub fn scan_columnar_segment( &self, segment_id: &str, ) -> Result<Vec<Vec<SqlValue>>>

Scan a columnar segment by string ID.

The segment ID format is {table_id}:{segment_id} (e.g., “12345:1”). Returns rows as a vector of SqlValue vectors.

Source

pub fn scan_columnar_segment_batches( &self, segment_id: &str, ) -> Result<Vec<RecordBatch>>

Scan a columnar segment by string ID, returning RecordBatches for streaming (FR-7).

This method returns raw RecordBatch objects, allowing the caller to iterate over rows without materializing all data upfront. Use this for large datasets where streaming is required.

The segment ID format is {table_id}:{segment_id} (e.g., “12345:1”).

Source

pub fn scan_columnar_segment_streaming( &self, segment_id: &str, ) -> Result<ColumnarRowIterator>

Create a streaming row iterator over a columnar segment (FR-7).

This returns a ColumnarRowIterator that yields rows one at a time from the underlying RecordBatches, without materializing all rows upfront.

The segment ID format is {table_id}:{segment_id} (e.g., “12345:1”).

Source

pub fn get_columnar_segment_stats( &self, segment_id: &str, ) -> Result<ColumnarSegmentStats>

Get statistics for a columnar segment by string ID.

The segment ID format is {table_id}:{segment_id} (e.g., “12345:1”).

Source

pub fn list_columnar_segments(&self) -> Result<Vec<String>>

List all columnar segments.

Returns segment IDs in the format {table_id}:{segment_id}.

Source

pub fn create_columnar_index( &self, segment_id: &str, column: &str, index_type: ColumnarIndexType, ) -> Result<()>

Create a columnar index for a segment/column.

Source

pub fn list_columnar_indexes( &self, segment_id: &str, ) -> Result<Vec<ColumnarIndexInfo>>

List columnar indexes for a segment.

Source

pub fn drop_columnar_index(&self, segment_id: &str, column: &str) -> Result<()>

Drop a columnar index for a segment/column.

Source

pub fn flush_in_memory_segment_to_file( &self, table: &str, segment_id: u64, path: &Path, ) -> Result<()>

InMemory モードのセグメントをファイルへフラッシュする。

Source

pub fn flush_in_memory_segment_to_kvs( &self, table: &str, segment_id: u64, ) -> Result<u64>

InMemory モードのセグメントを KVS へフラッシュする。

Source

pub fn flush_in_memory_segment_to_alopex( &self, table: &str, segment_id: u64, writer: &mut AlopexFileWriter, ) -> Result<u32>

InMemory モードのセグメントを .alopex ファイルへフラッシュする。

Source§

impl Database

Source

pub fn execute_sql(&self, sql: &str) -> Result<SqlResult>

SQL を実行する(auto-commit)。

  • DDL/DML は ReadWrite トランザクションで実行し、成功時に自動コミットする。
  • SELECT は ReadOnly トランザクションで実行する。
§Examples
use alopex_embedded::Database;
use alopex_sql::ExecutionResult;

let db = Database::new();
let result = db.execute_sql(
    "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);",
).unwrap();
assert!(matches!(result, ExecutionResult::Success));
Source

pub fn execute_sql_with_rows<F, R>( &self, sql: &str, f: F, ) -> Result<StreamingQueryResult<R>>
where F: FnOnce(StreamingRows<'_>) -> Result<R>,

Execute SQL with callback-based streaming for SELECT queries (FR-7).

This method provides true streaming by keeping the transaction alive during row iteration. The callback receives a StreamingRows that yields rows on-demand from storage.

§Type Parameters
  • F - Callback function that processes the streaming rows
  • R - Return type from the callback
§Examples
use alopex_embedded::Database;

let db = Database::new();
db.execute_sql("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);").unwrap();
db.execute_sql("INSERT INTO users (id, name) VALUES (1, 'Alice'), (2, 'Bob');").unwrap();

// Process rows with streaming - transaction stays alive during callback
let result = db.execute_sql_with_rows("SELECT * FROM users;", |mut rows| {
    let mut names = Vec::new();
    while let Ok(Some(row)) = rows.next_row() {
        if let Some(alopex_sql::storage::SqlValue::Text(name)) = row.get(1) {
            names.push(name.clone());
        }
    }
    Ok(names)
}).unwrap();
Source

pub fn execute_sql_streaming(&self, sql: &str) -> Result<SqlStreamingResult>

Execute SQL and return a streaming result for SELECT queries (FR-7).

This method returns a SqlStreamingResult that contains an iterator for query results, enabling true streaming output without materializing all rows upfront.

§Note

Only single SELECT statements are supported for streaming. Multi-statement SQL or non-SELECT statements fall back to the standard execution path.

§Examples
use alopex_embedded::{Database, SqlStreamingResult};

let db = Database::new();
db.execute_sql("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);").unwrap();
db.execute_sql("INSERT INTO users (id, name) VALUES (1, 'Alice');").unwrap();

let result = db.execute_sql_streaming("SELECT * FROM users;").unwrap();
if let SqlStreamingResult::Query(mut iter) = result {
    while let Ok(Some(row)) = iter.next_row() {
        println!("{:?}", row);
    }
}
Source§

impl Database

Source

pub fn open(path: &Path) -> Result<Self>

Opens a database at the specified path.

Source

pub fn new() -> Self

Creates a new, purely in-memory (transient) database.

Source

pub fn open_in_memory() -> Result<Self>

Opens a database in in-memory mode with default options.

Source

pub fn open_in_memory_with_options(opts: DatabaseOptions) -> Result<Self>

Opens a database in in-memory mode with the given options.

Source

pub fn open_with_uri(uri: &str) -> Result<Self>

Opens a database from a URI string.

Supported URI schemes:

  • file://path or bare path: Local filesystem
  • s3://bucket/prefix: S3-compatible storage (requires s3 feature)
§Example
// Local path
let db = Database::open_with_uri("/path/to/db")?;

// S3 URI (requires s3 feature and credentials)
let db = Database::open_with_uri("s3://my-bucket/data")?;
Source

pub fn table_info_cache_epoch(&self) -> u64

Returns the current table info cache epoch.

Source

pub fn get_cached_table_info( &self, catalog_name: &str, namespace_name: &str, table_name: &str, ) -> Option<CachedTableInfo>

Retrieves cached table info if available and epoch matches.

Source

pub fn cache_table_info( &self, catalog_name: &str, namespace_name: &str, table_name: &str, info: CachedTableInfo, )

Stores table info in the cache.

Source

pub fn invalidate_table_info_cache(&self)

Invalidates the table info cache (called on DDL operations).

Source

pub fn flush(&self) -> Result<()>

Flushes the current in-memory data to an SSTable on disk (beta).

Source

pub fn file_format_version(&self) -> FileVersion

Returns the file format version supported by the embedded engine.

Source

pub fn memory_usage(&self) -> Option<MemoryStats>

Returns current memory usage statistics (in-memory KV only).

Source

pub fn persist_to_disk(&self, wal_path: &Path) -> Result<()>

Persists the current in-memory database to disk atomically.

wal_path は「データディレクトリ」として扱う(file-mode)。

Source

pub fn clone_to_memory(&self) -> Result<Self>

Creates a fully in-memory clone of the current database.

Source

pub fn clear(&self) -> Result<()>

Clears all data while keeping the database usable.

Source

pub fn set_memory_limit(&self, bytes: Option<usize>)

Updates the memory limit in bytes for the underlying in-memory store.

Source

pub fn snapshot(&self) -> Vec<(Key, Vec<u8>)>

Returns a read-only snapshot of all key-value pairs.

Source

pub fn create_hnsw_index(&self, name: &str, config: HnswConfig) -> Result<()>

HNSW インデックスを作成し、永続化する。

Source

pub fn drop_hnsw_index(&self, name: &str) -> Result<()>

HNSW インデックスを削除する。

Source

pub fn get_hnsw_stats(&self, name: &str) -> Result<HnswStats>

HNSW 統計情報を取得する。

Source

pub fn compact_hnsw_index(&self, name: &str) -> Result<CompactionResult>

HNSW インデックスをコンパクションし、結果を返す。

Source

pub fn search_hnsw( &self, name: &str, query: &[f32], k: usize, ef_search: Option<usize>, ) -> Result<(Vec<HnswSearchResult>, HnswSearchStats)>

HNSW インデックスに検索を行う。

Source

pub fn create_blob_writer( &self, path: &Path, total_len: u64, chunk_size: Option<u32>, ) -> Result<LargeValueWriter>

Creates a chunked large value writer for opaque blobs (beta).

Source

pub fn create_typed_writer( &self, path: &Path, type_id: u16, total_len: u64, chunk_size: Option<u32>, ) -> Result<LargeValueWriter>

Creates a chunked large value writer for typed payloads (beta).

Source

pub fn open_large_value(&self, path: &Path) -> Result<LargeValueReader>

Opens a chunked large value reader (beta). Kind/type is read from the file header.

Source

pub fn begin(&self, mode: TxnMode) -> Result<Transaction<'_>>

Begins a new transaction.

Trait Implementations§

Source§

impl Default for Database

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,