我无法在我的架构中写入任何内容,并且不会抛出任何错误或异常。
这是我声明的架构,
const CollectionSchema = {
name: 'Collection',
primaryKey: 'ID',
properties: {
ID: 'string',// primary key
ItemId: 'int',
Condition: 'int',
Packaging: 'int',
ConditionNotes: {type: 'string', optional: true},
OriginalRestored: {type: 'bool', optional: true},
PricePaid: {type: 'int', optional: true},
AcquiredFrom: {type: 'string', optional: true},
MoreDetails: {type: 'string', optional: true},
DatePurchased: {type: 'date', optional: true},
PrivateNotes: {type: 'string', optional: true},
StorageLocation: {type: 'string', optional: true}
}
};
这是我写入架构的函数,
addCollection(){
Realm.open({schema: [CollectionSchema]})
.then(realm => {
try {
realm.write(() => {
realm.create('Collection',
{
ID: this.state.ID,
ItemId: this.state.itemId,
Condition: this.state.condition,
Packaging: this.state.packaging,
ConditionNotes: this.state.conditionNotes,
OriginalRestored: this.state.originalRestored,
PricePaid: this.state.pricePaid,
AcquiredFrom: this.state.acquiredFrom,
MoreDetails: this.state.moreDetails,
DatePurchased: new Date(this.state.datePurchased),
PrivateNotes: this.state.privateNotes,
StorageLocation: this.state.storageLocation
});
});
} catch (e) {
console.log("Error:"+ e);
}
});
}
我犯了什么错误?
编辑:
以下是package.json
,
"dependencies": {
"react": "16.0.0-alpha.12",
"react-native": "^0.47.2",
"realm": "^1.11.1"
},
以下是我如何创建ID
createIndex(){
let table = realm.objects('Collection').sorted('ID', true);
if(table.length<1){
return 1;
}
let highestId = table[0].ID;
return highestId+1;
}