pub struct Database { /* private fields */ }Expand description
The main database object.
Implementations§
Source§impl Database
impl Database
Sourcepub fn list_catalogs(&self) -> Result<Vec<CatalogInfo>>
pub fn list_catalogs(&self) -> Result<Vec<CatalogInfo>>
Catalog 一覧を取得する。
Sourcepub fn get_catalog(&self, name: &str) -> Result<CatalogInfo>
pub fn get_catalog(&self, name: &str) -> Result<CatalogInfo>
Catalog を取得する。
Sourcepub fn list_namespaces(&self, catalog_name: &str) -> Result<Vec<NamespaceInfo>>
pub fn list_namespaces(&self, catalog_name: &str) -> Result<Vec<NamespaceInfo>>
Namespace 一覧を取得する。
Sourcepub fn get_namespace(
&self,
catalog_name: &str,
namespace_name: &str,
) -> Result<NamespaceInfo>
pub fn get_namespace( &self, catalog_name: &str, namespace_name: &str, ) -> Result<NamespaceInfo>
Namespace を取得する。
Sourcepub fn list_tables(
&self,
catalog_name: &str,
namespace_name: &str,
) -> Result<Vec<TableInfo>>
pub fn list_tables( &self, catalog_name: &str, namespace_name: &str, ) -> Result<Vec<TableInfo>>
テーブル一覧を取得する。
Sourcepub fn list_tables_simple(&self) -> Result<Vec<TableInfo>>
pub fn list_tables_simple(&self) -> Result<Vec<TableInfo>>
デフォルト catalog/namespace のテーブル一覧を取得する。
Sourcepub fn get_table_info(
&self,
catalog_name: &str,
namespace_name: &str,
table_name: &str,
) -> Result<TableInfo>
pub fn get_table_info( &self, catalog_name: &str, namespace_name: &str, table_name: &str, ) -> Result<TableInfo>
テーブル情報を取得する。
Sourcepub fn get_table_info_simple(&self, table_name: &str) -> Result<TableInfo>
pub fn get_table_info_simple(&self, table_name: &str) -> Result<TableInfo>
デフォルト catalog/namespace のテーブル情報を取得する。
Sourcepub fn get_table_info_cached(
&self,
catalog_name: &str,
namespace_name: &str,
table_name: &str,
) -> Result<CachedTableInfo>
pub fn get_table_info_cached( &self, catalog_name: &str, namespace_name: &str, table_name: &str, ) -> Result<CachedTableInfo>
テーブル情報をキャッシュから取得する(キャッシュミス時は DB ルックアップ)。
パフォーマンス最適化のため、キャッシュを使用してテーブルメタデータを取得する。 DDL 操作(テーブル作成/削除など)が発生するとキャッシュは自動的に無効化される。
Sourcepub fn list_indexes(
&self,
catalog_name: &str,
namespace_name: &str,
table_name: &str,
) -> Result<Vec<IndexInfo>>
pub fn list_indexes( &self, catalog_name: &str, namespace_name: &str, table_name: &str, ) -> Result<Vec<IndexInfo>>
インデックス一覧を取得する。
Sourcepub fn list_indexes_simple(&self, table_name: &str) -> Result<Vec<IndexInfo>>
pub fn list_indexes_simple(&self, table_name: &str) -> Result<Vec<IndexInfo>>
デフォルト catalog/namespace のインデックス一覧を取得する。
Sourcepub fn get_index_info(
&self,
catalog_name: &str,
namespace_name: &str,
table_name: &str,
index_name: &str,
) -> Result<IndexInfo>
pub fn get_index_info( &self, catalog_name: &str, namespace_name: &str, table_name: &str, index_name: &str, ) -> Result<IndexInfo>
インデックス情報を取得する。
Sourcepub fn get_index_info_simple(
&self,
table_name: &str,
index_name: &str,
) -> Result<IndexInfo>
pub fn get_index_info_simple( &self, table_name: &str, index_name: &str, ) -> Result<IndexInfo>
デフォルト catalog/namespace のインデックス情報を取得する。
Sourcepub fn create_catalog(
&self,
request: CreateCatalogRequest,
) -> Result<CatalogInfo>
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");Sourcepub fn create_namespace(
&self,
request: CreateNamespaceRequest,
) -> Result<NamespaceInfo>
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");Sourcepub fn delete_namespace(
&self,
catalog_name: &str,
namespace_name: &str,
force: bool,
) -> Result<()>
pub fn delete_namespace( &self, catalog_name: &str, namespace_name: &str, force: bool, ) -> Result<()>
Namespace を削除する。
Sourcepub fn create_table(&self, request: CreateTableRequest) -> Result<TableInfo>
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");Sourcepub fn create_table_simple(
&self,
name: &str,
schema: Vec<ColumnDefinition>,
) -> Result<TableInfo>
pub fn create_table_simple( &self, name: &str, schema: Vec<ColumnDefinition>, ) -> Result<TableInfo>
デフォルト catalog/namespace のテーブルを作成する。
Sourcepub fn delete_table(
&self,
catalog_name: &str,
namespace_name: &str,
table_name: &str,
) -> Result<()>
pub fn delete_table( &self, catalog_name: &str, namespace_name: &str, table_name: &str, ) -> Result<()>
テーブルを削除する。
Sourcepub fn delete_table_simple(&self, name: &str) -> Result<()>
pub fn delete_table_simple(&self, name: &str) -> Result<()>
デフォルト catalog/namespace のテーブルを削除する。
Source§impl Database
impl Database
Sourcepub fn open_with_config(config: EmbeddedConfig) -> Result<Self>
pub fn open_with_config(config: EmbeddedConfig) -> Result<Self>
構成付きでデータベースを開く(カラムナー機能を初期化)。
Sourcepub fn storage_mode(&self) -> StorageMode
pub fn storage_mode(&self) -> StorageMode
現在のカラムナーストレージモードを返す。
Sourcepub fn write_columnar_segment(
&self,
table: &str,
batch: RecordBatch,
) -> Result<u64>
pub fn write_columnar_segment( &self, table: &str, batch: RecordBatch, ) -> Result<u64>
カラムナーセグメントを書き込む。
Sourcepub fn write_columnar_segment_with_config(
&self,
table: &str,
batch: RecordBatch,
config: SegmentConfigV2,
) -> Result<u64>
pub fn write_columnar_segment_with_config( &self, table: &str, batch: RecordBatch, config: SegmentConfigV2, ) -> Result<u64>
カラムナーセグメントを書き込む(構成上書き)。
Sourcepub fn read_columnar_segment(
&self,
table: &str,
segment_id: u64,
columns: Option<&[&str]>,
) -> Result<Vec<RecordBatch>>
pub fn read_columnar_segment( &self, table: &str, segment_id: u64, columns: Option<&[&str]>, ) -> Result<Vec<RecordBatch>>
カラムナーセグメントを読み取る(カラム名指定オプション付き)。
Sourcepub fn in_memory_usage(&self) -> Option<u64>
pub fn in_memory_usage(&self) -> Option<u64>
InMemory モード時のメモリ使用量を返す。Disk モードでは None。
Sourcepub fn open_in_memory_with_limit(limit: usize) -> Result<Self>
pub fn open_in_memory_with_limit(limit: usize) -> Result<Self>
メモリ上限付きでインメモリ DB を開く。
Sourcepub fn resolve_table_id(&self, table: &str) -> Result<u32>
pub fn resolve_table_id(&self, table: &str) -> Result<u32>
テーブル名から内部 ID を解決する。
Sourcepub fn scan_columnar_segment(
&self,
segment_id: &str,
) -> Result<Vec<Vec<SqlValue>>>
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.
Sourcepub fn scan_columnar_segment_batches(
&self,
segment_id: &str,
) -> Result<Vec<RecordBatch>>
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”).
Sourcepub fn scan_columnar_segment_streaming(
&self,
segment_id: &str,
) -> Result<ColumnarRowIterator>
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”).
Sourcepub fn get_columnar_segment_stats(
&self,
segment_id: &str,
) -> Result<ColumnarSegmentStats>
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”).
Sourcepub fn list_columnar_segments(&self) -> Result<Vec<String>>
pub fn list_columnar_segments(&self) -> Result<Vec<String>>
List all columnar segments.
Returns segment IDs in the format {table_id}:{segment_id}.
Sourcepub fn create_columnar_index(
&self,
segment_id: &str,
column: &str,
index_type: ColumnarIndexType,
) -> Result<()>
pub fn create_columnar_index( &self, segment_id: &str, column: &str, index_type: ColumnarIndexType, ) -> Result<()>
Create a columnar index for a segment/column.
Sourcepub fn list_columnar_indexes(
&self,
segment_id: &str,
) -> Result<Vec<ColumnarIndexInfo>>
pub fn list_columnar_indexes( &self, segment_id: &str, ) -> Result<Vec<ColumnarIndexInfo>>
List columnar indexes for a segment.
Sourcepub fn drop_columnar_index(&self, segment_id: &str, column: &str) -> Result<()>
pub fn drop_columnar_index(&self, segment_id: &str, column: &str) -> Result<()>
Drop a columnar index for a segment/column.
Sourcepub fn flush_in_memory_segment_to_file(
&self,
table: &str,
segment_id: u64,
path: &Path,
) -> Result<()>
pub fn flush_in_memory_segment_to_file( &self, table: &str, segment_id: u64, path: &Path, ) -> Result<()>
InMemory モードのセグメントをファイルへフラッシュする。
Sourcepub fn flush_in_memory_segment_to_kvs(
&self,
table: &str,
segment_id: u64,
) -> Result<u64>
pub fn flush_in_memory_segment_to_kvs( &self, table: &str, segment_id: u64, ) -> Result<u64>
InMemory モードのセグメントを KVS へフラッシュする。
Sourcepub fn flush_in_memory_segment_to_alopex(
&self,
table: &str,
segment_id: u64,
writer: &mut AlopexFileWriter,
) -> Result<u32>
pub fn flush_in_memory_segment_to_alopex( &self, table: &str, segment_id: u64, writer: &mut AlopexFileWriter, ) -> Result<u32>
InMemory モードのセグメントを .alopex ファイルへフラッシュする。
Source§impl Database
impl Database
Sourcepub fn execute_sql(&self, sql: &str) -> Result<SqlResult>
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));Sourcepub fn execute_sql_with_rows<F, R>(
&self,
sql: &str,
f: F,
) -> Result<StreamingQueryResult<R>>
pub fn execute_sql_with_rows<F, R>( &self, sql: &str, f: F, ) -> Result<StreamingQueryResult<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 rowsR- 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();Sourcepub fn execute_sql_streaming(&self, sql: &str) -> Result<SqlStreamingResult>
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
impl Database
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
Opens a database in in-memory mode with default options.
Sourcepub fn open_in_memory_with_options(opts: DatabaseOptions) -> Result<Self>
pub fn open_in_memory_with_options(opts: DatabaseOptions) -> Result<Self>
Opens a database in in-memory mode with the given options.
Sourcepub fn open_with_uri(uri: &str) -> Result<Self>
pub fn open_with_uri(uri: &str) -> Result<Self>
Opens a database from a URI string.
Supported URI schemes:
file://pathor bare path: Local filesystems3://bucket/prefix: S3-compatible storage (requiress3feature)
§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")?;Sourcepub fn table_info_cache_epoch(&self) -> u64
pub fn table_info_cache_epoch(&self) -> u64
Returns the current table info cache epoch.
Sourcepub fn get_cached_table_info(
&self,
catalog_name: &str,
namespace_name: &str,
table_name: &str,
) -> Option<CachedTableInfo>
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.
Sourcepub fn cache_table_info(
&self,
catalog_name: &str,
namespace_name: &str,
table_name: &str,
info: CachedTableInfo,
)
pub fn cache_table_info( &self, catalog_name: &str, namespace_name: &str, table_name: &str, info: CachedTableInfo, )
Stores table info in the cache.
Sourcepub fn invalidate_table_info_cache(&self)
pub fn invalidate_table_info_cache(&self)
Invalidates the table info cache (called on DDL operations).
Sourcepub fn flush(&self) -> Result<()>
pub fn flush(&self) -> Result<()>
Flushes the current in-memory data to an SSTable on disk (beta).
Sourcepub fn file_format_version(&self) -> FileVersion
pub fn file_format_version(&self) -> FileVersion
Returns the file format version supported by the embedded engine.
Sourcepub fn memory_usage(&self) -> Option<MemoryStats>
pub fn memory_usage(&self) -> Option<MemoryStats>
Returns current memory usage statistics (in-memory KV only).
Sourcepub fn persist_to_disk(&self, wal_path: &Path) -> Result<()>
pub fn persist_to_disk(&self, wal_path: &Path) -> Result<()>
Persists the current in-memory database to disk atomically.
wal_path は「データディレクトリ」として扱う(file-mode)。
Sourcepub fn clone_to_memory(&self) -> Result<Self>
pub fn clone_to_memory(&self) -> Result<Self>
Creates a fully in-memory clone of the current database.
Sourcepub fn set_memory_limit(&self, bytes: Option<usize>)
pub fn set_memory_limit(&self, bytes: Option<usize>)
Updates the memory limit in bytes for the underlying in-memory store.
Sourcepub fn snapshot(&self) -> Vec<(Key, Vec<u8>)>
pub fn snapshot(&self) -> Vec<(Key, Vec<u8>)>
Returns a read-only snapshot of all key-value pairs.
Sourcepub fn create_hnsw_index(&self, name: &str, config: HnswConfig) -> Result<()>
pub fn create_hnsw_index(&self, name: &str, config: HnswConfig) -> Result<()>
HNSW インデックスを作成し、永続化する。
Sourcepub fn drop_hnsw_index(&self, name: &str) -> Result<()>
pub fn drop_hnsw_index(&self, name: &str) -> Result<()>
HNSW インデックスを削除する。
Sourcepub fn get_hnsw_stats(&self, name: &str) -> Result<HnswStats>
pub fn get_hnsw_stats(&self, name: &str) -> Result<HnswStats>
HNSW 統計情報を取得する。
Sourcepub fn compact_hnsw_index(&self, name: &str) -> Result<CompactionResult>
pub fn compact_hnsw_index(&self, name: &str) -> Result<CompactionResult>
HNSW インデックスをコンパクションし、結果を返す。
Sourcepub fn search_hnsw(
&self,
name: &str,
query: &[f32],
k: usize,
ef_search: Option<usize>,
) -> Result<(Vec<HnswSearchResult>, HnswSearchStats)>
pub fn search_hnsw( &self, name: &str, query: &[f32], k: usize, ef_search: Option<usize>, ) -> Result<(Vec<HnswSearchResult>, HnswSearchStats)>
HNSW インデックスに検索を行う。
Sourcepub fn create_blob_writer(
&self,
path: &Path,
total_len: u64,
chunk_size: Option<u32>,
) -> Result<LargeValueWriter>
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).
Sourcepub fn create_typed_writer(
&self,
path: &Path,
type_id: u16,
total_len: u64,
chunk_size: Option<u32>,
) -> Result<LargeValueWriter>
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).
Sourcepub fn open_large_value(&self, path: &Path) -> Result<LargeValueReader>
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.
Sourcepub fn begin(&self, mode: TxnMode) -> Result<Transaction<'_>>
pub fn begin(&self, mode: TxnMode) -> Result<Transaction<'_>>
Begins a new transaction.