A record entry can contain fields of differing types. However, embedded records should be used only when the data is relatively static. In general, child tables provide a better solution over embedded records, especially if the child dataset is large or is likely to change in size.
Use the RECORD()
statement to declare a
table field as a record.
To define a simple two-field table where the primary key is a UID and the second field contains a record, you use the following DDL statement:
CREATE TABLE myTable ( uid INTEGER, myRecord RECORD(firstField STRING, secondField INTEGER), PRIMARY KEY (uid) )
CHECK
, DEFAULT
and NOT NULL
constraints are not supported for embedded record fields.
However, these constraints can be applied to the individual
fields in an embedded record. See
Field Constraints
for more information.
To write the embedded record, create it as a Javascript object:
var mrec = {firstField: "An embedded record", secondField: 3388}; var row = {uid: 0, myRecord: mrec }; store.put('myTable', row, function (err) { if (err) throw err; else { console.log("Row inserted."); } });
Then, you can read the field in the usual way:
var primaryKey = {uid: 0}; store.get('myTable', primaryKey, function (err, returnRow) { if (err) throw err; else { console.log(returnRow.currentRow.myRecord); store.close(); } });