[−][src]Module dbcrossbarlib::schema
Our "interchange" format for database table schemas.
To convert table schemas between different databases, we have a choice:
- We can convert between each pair of schema formats directly, which would
require
2*n*(n-1)
conversions forn
databases. - We can define an "interchange" format, and then build
n
input conversions andn
output conversions. This is much simpler.
A good interchange format should be rich enough to include the most common database types, including not just obvious things like text and integers, but also things like timestamps and geodata. But a good interchange format should also be as simple as possible, omitting details that generally don't translate well.
Inevitably, this means that we're going to wind up with a subjective and opinionated design.
We define our format using Rust data structures, which are serialized and
deserialized using serde
.
use dbcrossbarlib::schema::Table; use serde_json; let json = r#" { "name": "example", "columns": [ { "name": "a", "is_nullable": true, "data_type": "text" }, { "name": "b", "is_nullable": true, "data_type": "int32" }, { "name": "c", "is_nullable": false, "data_type": "uuid" }, { "name": "d", "is_nullable": true, "data_type": "date" }, { "name": "e", "is_nullable": true, "data_type": "float64" }, { "name": "f", "is_nullable": true, "data_type": { "array": "text" } }, { "name": "h", "is_nullable": true, "data_type": { "geo_json": 4326 } } ] } "#; let table: Table = serde_json::from_str(json).expect("could not parse JSON");
Structs
Column | Information about a column. |
Srid | An SRID number specifying how to intepret geographical coordinates. |
Table | Information about a table. |
Enums
DataType | The data type of a column. |