BaseEntity
BaseEntity is an optional base class an @Entity-decorated class can
extend to pick up a small set of convenience instance methods. Extending it is not required —
a plain class with @Entity/@Column decorators works fine as a
Repository<T> target too. See
Defining Models → Extending BaseEntity
for the guide-level walkthrough.
class BaseEntity {
constructor(partial?: any);
destroy(): Promise<boolean>;
exists(): Promise<boolean>;
toJSON(): any;
}
Constructor
new BaseEntity(partial?: any)
Copies matching column-field values from partial onto the new instance — it reads the class's
own column field names via Entity.getColumnFieldNames() and, for each one present and not
undefined on partial, assigns it onto this:
class Customer extends BaseEntity {
@Column()
declare givenName?: string;
}
new Customer({ givenName: 'Jane' }); // { givenName: 'Jane' }
Methods
destroy()
destroy(): Promise<boolean>
Intended to delegate to repo.delete(this) on whatever Repository produced the instance, via a
private, symbol-keyed back-reference field (REPOSITORY_KEY) declared on the class.
Reading the full @sqb/connect ORM source (orm/base-entity.ts, orm/orm.const.ts, and every
command/row-conversion file under orm/commands/) turns up no code that ever assigns that
private field — it's declared (private [REPOSITORY_KEY]?: Repository<any>) but nothing sets it
after a Repository call, including Repository.create()/findById()/findMany()/etc. and the
row-conversion code in orm/commands/row-converter.ts (which sets the returned object's
prototype to the entity class, but never touches this field). As shipped, that means
this[REPOSITORY_KEY] is always undefined, and both destroy() and exists() below always
resolve to false — regardless of whether the instance came from a Repository call or was
constructed directly. Double-check against the installed version's source if you're relying on
either method to actually delete/check a row; as of this version, they don't wire up as their own
implementation implies.
exists()
exists(): Promise<boolean>
Intended to delegate to repo.exists(this) on the producing Repository, through the same
unwired back-reference described above — see the caution under destroy().
toJSON()
toJSON(): any
Returns this unchanged. The source carries a comment stating this is "a placeholder and will be
overwritten by declareEntity() method" — no declareEntity() function exists anywhere in the
current @sqb/connect source, so that comment does not correspond to any mechanism present in
this version; as shipped, toJSON() is a plain pass-through.