Skip to main content

surreal_sync_core/
lib.rs

1//! Core types for the surreal-sync framework.
2//!
3//! This crate provides the foundational types used across the sync
4//! framework, including:
5//!
6//! - [`Type`] - Universal type representation for all supported databases
7//! - [`Value`] - Raw generated values before type conversion
8//! - [`TypedValue`] - Values with type information for conversion
9//! - [`Row`] - Intermediate row representation
10//! - [`Schema`] - Schema definitions loaded from YAML
11//!
12//! # Architecture
13//!
14//! The `surreal-sync-core` crate sits at the foundation of the sync framework:
15//!
16//! ```text
17//! surreal-sync-core (this crate)
18//!    │
19//!    ├─── loadtest-generator  (depends on surreal-sync-core for types)
20//!    │
21//!    ├─── surreal-sync-mysql  (implements From/Into for MySQL)
22//!    ├─── surreal-sync-postgresql::types    (implements From/Into for PostgreSQL)
23//!    ├─── mongodb-types       (implements From/Into for MongoDB)
24//!    ├─── surrealdb-types     (implements From/Into for SurrealDB)
25//!    └─── surreal-sync-json::types          (implements From/Into for JSON/CSV)
26//! ```
27//!
28//! # Example
29//!
30//! ```rust
31//! use surreal_sync_core::types::Type;
32//! use surreal_sync_core::values::{Value, TypedValue};
33//!
34//! // Create a typed value using factory methods
35//! let value = TypedValue::int32(42);
36//!
37//! // For dynamic types (e.g., from schema), use try_with_type for validation:
38//! let dynamic_value = TypedValue::try_with_type(
39//!     Type::Int32,
40//!     Value::Int32(42)
41//! ).expect("valid type-value combination");
42//!
43//! // Type-specific crates implement From<TypedValue> for their native types:
44//! // let mysql_value: MySQLValue = value.into();
45//! ```
46
47pub mod checkpoint;
48pub mod foreign_keys;
49pub mod id_columns;
50pub mod relation_change;
51pub mod schema;
52pub mod sink;
53pub mod transform;
54pub mod types;
55pub mod values;
56
57// Re-exports for convenience
58// Checkpoint API (storage backends live in separate crates)
59pub use sink::{SinkConnect, SinkWithCheckpoints, SurrealConfig, SurrealSdkVersion, SurrealSink};
60
61pub use checkpoint::{
62    Checkpoint, CheckpointFile, CheckpointID, CheckpointStorage, CheckpointStore,
63    InterleavedSnapshotCheckpoint, NullStore, NullSyncManager, SnapshotCheckpointer,
64    SnapshotTableProgress, StoredCheckpoint, SyncConfig, SyncManager, SyncPhase,
65};
66
67pub use transform::{InPlaceTransform, Passthrough};
68
69// Foreign key types
70pub use foreign_keys::{classify_table, ForeignKeyDefinition, TableKind};
71
72// ID / primary-key column helpers
73pub use id_columns::{
74    apply_id_column_overrides, build_composite_record_id, flatten_composite_id,
75    parse_id_column_overrides, stringify_id_part, IdColumnOverrides, IdColumnsError,
76};
77
78// Base types (context-neutral, no generators)
79pub use schema::{ColumnDefinition, DatabaseSchema, TableDefinition};
80
81// Generator types (with generators)
82pub use schema::{
83    FieldDefinition, GeneratorConfig, GeneratorFieldDefinition, GeneratorIDDefinition,
84    GeneratorSchema, GeneratorTableDefinition, IDDefinition, Schema, SchemaError,
85    TableDefinitionWithGenerators,
86};
87
88// Legacy alias for backwards compatibility
89#[deprecated(since = "1.0.0", note = "Use GeneratorSchema instead")]
90pub type LoadTestSchema = Schema;
91pub use relation_change::RelationChange;
92pub use types::{GeometryType, ToDdl, Type};
93pub use values::{
94    Change, ChangeOp, GeometryData, Relation, Row, RowBuilder, RowConverter, ThingRef, TypedValue,
95    TypedValueError, Value, ZeroTemporalPolicy,
96};