[][src]Module dbcrossbarlib::schema

Our "interchange" format for database table schemas.

To convert table schemas between different databases, we have a choice:

  1. We can convert between each pair of schema formats directly, which would require 2*n*(n-1) conversions for n databases.
  2. We can define an "interchange" format, and then build n input conversions and n 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 } },
    { "name": "g", "is_nullable": true,  "data_type": { "struct": [
      { "name": "x", "data_type": "float64", "is_nullable": false },
      { "name": "y", "data_type": "float64", "is_nullable": false }
    ] } }

let table: Table = serde_json::from_str(json).expect("could not parse JSON");



Information about a column.


An SRID number specifying how to intepret geographical coordinates.


Information about a named field.


Information about a table.



The data type of a column.