Custom Schema Definitions
You can extend the HarperDB table schemas discovered by the driver by saving them into schema files. The schema files have a simple format that makes the schemas easy to edit.
Generating Schema Files
Use the driver's CreateDriverSchema stored procedure to generate a driver schema file for a table:
"EXECUTE CreateDriverSchema @TableName='restaurants', @FileName='C:/Users/Public/restaurants.rsd'".
For example, consider a schema for a table of restaurant data.
Below is an example document from the collection:
{ "address":{ "building":"461", "coord":[ -74.138492, 40.631136 ], "street":"Port Richmond Ave", "zipcode":"10302" }, "borough":"Staten Island", "cuisine":"Other", "name":"Indian Oven", "restaurant_id":"50018994" }
Customizing a Schema
To use driver schema files, set the Location property to the folder path where the schema files are saved on your machine . You can then change column behavior in the generated schemas.
The following schema uses the other:xpath property to define where in an object or array in the document the driver should retrieve the data for a particular column. Using this model you can flatten arbitrary levels of hierarchy.
Below are the column definitions and the table to extract the column values from. In Custom Schema Example, you will find the complete schema.
<rsb:script xmlns:rsb="http://www.rssbus.com/ns/rsbscript/2">
<rsb:info title="StaticRestaurants" description="Custom Schema for the restaurants data set.">
<!-- Column definitions -->
<attr name="borough" xs:type="string" />
<attr name="cuisine" xs:type="string" />
<attr name="building" xs:type="string" other:xpath="address/building" />
<attr name="street" xs:type="string" other:bsonpath="address/street" />
<attr name="latitude" xs:type="double" other:bsonpath="address/coord[0]" />
<attr name="longitude" xs:type="double" other:bsonpath="address/coord[1]" />
</rsb:info>
</rsb:script>