-
Notifications
You must be signed in to change notification settings - Fork 127
Defining table schemas
Table schemas are represented in SquiDB with subclasses of TableModel. While it is possible to write TableModel subclasses by hand, nearly always you will want to use the SquiDB code generator. TableModel subclasses tend to be a bit verbose and repetitive, so SquiDB includes a code generation tool that will write your TableModel subclasses for you using compile-time annotation processing. This enables developers to define their table schemas in much simpler Java classes, which we refer to as "Model specs" after the annotations used to mark them for processing by the code generator.
Here's an example of a model spec class:
@TableModelSpec(className="Person", tableName="people")
public class PersonSpec {
public String firstName;
public String lastName;
public int age;
}
This corresponds to a schema for a table named "people". The table will be represented by a subclass of TableModel named "Person" and have four columns: an automatically generated primary key column named "_id", a text column named "firstName", a text column named "lastName", and a numeric column named "age".
The supported types you can use to declare columns are:
- any Java primitive or any boxed version thereof (int/Integer, boolean/Boolean, etc.)
- String
- byte[] (for blobs)
See also: