All map entries must be of the same type. Regardless of the type of the map's values, its keys are always strings.
The string "[]" is reserved and must not be used for key names.
When you declare a table field as a map, you use
the MAP()
statement. You must also declare
the map element's data types.
To define a simple two-field table where the primary key is a UID and the second field contains a map of integers, you use the following DDL statement:
CREATE TABLE myTable ( uid INTEGER, myMap MAP(INTEGER), PRIMARY KEY (uid) )
CHECK
constraints are supported for map
fields. See CHECK
for more information.
DEFAULT
and NOT NULL
constraints are not supported for map fields.
To write the map:
var mmap = {field1: 1, field2: 2, field3: 3}; var row = {uid: 0, myMap: mmap }; store.put('myTable', row, function (err) { if (err) throw err; else { console.log("Row inserted."); } });
To read map field2:
var primaryKey = {uid: 0}; store.get('myTable', primaryKey, function (err, returnRow) { if (err) throw err; else { console.log(returnRow.currentRow.myMap.field2); store.close(); } });