ModelBase
Defined in: .work/repos/edinburgh/src/models.ts:491
Minimal instance-side model shape used for typing the constructor property.
Type Parameters
Section titled “Type Parameters”LOOKUP
Section titled “LOOKUP”LOOKUP extends ModelLookup = ModelLookup
Properties
Section titled “Properties”constructor
Section titled “constructor”constructor:
LOOKUP&object&ModelClassRuntime<any, readonlyany[],any,any> & (initial?,txn?) =>any
Defined in: .work/repos/edinburgh/src/models.ts:492
_primaryKey
Section titled “_primaryKey”_primaryKey:
Uint8Array<ArrayBufferLike>
Defined in: .work/repos/edinburgh/src/models.ts:706
_primaryKeyHash
Section titled “_primaryKeyHash”_primaryKeyHash:
number
Defined in: .work/repos/edinburgh/src/models.ts:707
_txn:
Transaction
Defined in: .work/repos/edinburgh/src/models.ts:708
Methods
Section titled “Methods”preCommit()?
Section titled “preCommit()?”
optionalpreCommit():void
Defined in: .work/repos/edinburgh/src/models.ts:733
Optional hook called on each modified instance right before the transaction commits. Runs before data is written to disk, so changes made here are included in the commit.
Common use cases:
- Computing derived or denormalized fields
- Enforcing cross-field validation rules
- Creating or updating related model instances (newly created instances will also
have their
preCommit()called)
Returns
Section titled “Returns”void
Example
Section titled “Example”const Post = E.defineModel("Post", class { id = E.field(E.identifier); title = E.field(E.string); slug = E.field(E.string);
preCommit() { this.slug = this.title.toLowerCase().replace(/\s+/g, "-"); }}, { pk: "id" });_setLoadedField()
Section titled “_setLoadedField()”_setLoadedField(
fieldName,value):void
Defined in: .work/repos/edinburgh/src/models.ts:735
Parameters
Section titled “Parameters”fieldName
Section titled “fieldName”string
any
Returns
Section titled “Returns”void
_restoreLazyFields()
Section titled “_restoreLazyFields()”_restoreLazyFields():
void
Defined in: .work/repos/edinburgh/src/models.ts:749
Returns
Section titled “Returns”void
getPrimaryKey()
Section titled “getPrimaryKey()”getPrimaryKey():
Uint8Array
Defined in: .work/repos/edinburgh/src/models.ts:762
Returns
Section titled “Returns”Uint8Array
The primary key for this instance.
_setPrimaryKey()
Section titled “_setPrimaryKey()”_setPrimaryKey(
key,hash?):void
Defined in: .work/repos/edinburgh/src/models.ts:772
Parameters
Section titled “Parameters”Uint8Array
number
Returns
Section titled “Returns”void
getPrimaryKeyHash()
Section titled “getPrimaryKeyHash()”getPrimaryKeyHash():
number
Defined in: .work/repos/edinburgh/src/models.ts:781
Returns
Section titled “Returns”number
A 53-bit positive integer non-cryptographic hash of the primary key, or undefined if not yet saved.
isLazyField()
Section titled “isLazyField()”isLazyField(
field):boolean
Defined in: .work/repos/edinburgh/src/models.ts:786
Parameters
Section titled “Parameters”keyof ModelBase<LOOKUP>
Returns
Section titled “Returns”boolean
_write()
Section titled “_write()”_write(
txn):Change
Defined in: .work/repos/edinburgh/src/models.ts:791
Parameters
Section titled “Parameters”Returns
Section titled “Returns”preventPersist()
Section titled “preventPersist()”preventPersist():
ModelBase<LOOKUP>
Defined in: .work/repos/edinburgh/src/models.ts:881
Prevent this instance from being persisted to the database.
Returns
Section titled “Returns”ModelBase<LOOKUP>
This model instance for chaining.
Example
Section titled “Example”const user = User.get("user123");user.name = "New Name";user.preventPersist(); // Changes won't be saveddelete()
Section titled “delete()”delete():
void
Defined in: .work/repos/edinburgh/src/models.ts:902
Delete this model instance from the database.
Removes the instance and all its index entries from the database and prevents further persistence.
Returns
Section titled “Returns”void
Example
Section titled “Example”const user = User.get("user123");user.delete(); // Removes from databasevalidate()
Section titled “validate()”validate(
raise?):Error[]
Defined in: .work/repos/edinburgh/src/models.ts:921
Validate all fields in this model instance.
Parameters
Section titled “Parameters”raise?
Section titled “raise?”boolean = false
If true, throw on first validation error.
Returns
Section titled “Returns”Error[]
Array of validation errors (empty if valid).
Example
Section titled “Example”const user = new User();const errors = user.validate();if (errors.length > 0) { console.log("Validation failed:", errors);}isValid()
Section titled “isValid()”isValid():
boolean
Defined in: .work/repos/edinburgh/src/models.ts:946
Check if this model instance is valid.
Returns
Section titled “Returns”boolean
true if all validations pass.
Example
Section titled “Example”const user = new User({name: "John"});if (!user.isValid()) shoutAtTheUser();getState()
Section titled “getState()”getState():
"created"|"deleted"|"loaded"|"lazy"
Defined in: .work/repos/edinburgh/src/models.ts:950
Returns
Section titled “Returns”"created" | "deleted" | "loaded" | "lazy"
toString()
Section titled “toString()”toString():
string
Defined in: .work/repos/edinburgh/src/models.ts:961
Returns
Section titled “Returns”string