GraphEntityBase
Defined in: rxdb-plugin-graph/src/GraphEntityBase.ts:26
图实体装饰器配置 定义了图结构所需的边关系和遍历能力
Extends
Constructors
Constructor
new GraphEntityBase(_initData?): GraphEntityBase;
Defined in: rxdb/dist/entity/EntityBase.d.ts:96
实体基类构造函数 子类会通过 Entity 装饰器增强此构造函数
Parameters
| Parameter | Type | Description |
|---|---|---|
_initData? | any | 可选的初始化数据 |
Returns
GraphEntityBase
Inherited from
Properties
createdAt
readonly createdAt: Date;
Defined in: rxdb/dist/entity/EntityBase.d.ts:20
创建时间 实体创建时自动设置为当前时间
Inherited from
createdBy?
readonly optional createdBy: `${string}-${string}-${string}-${string}-${string}` | null;
Defined in: rxdb/dist/entity/EntityBase.d.ts:30
创建者ID 记录创建此实体的用户ID
Inherited from
id
readonly id: `${string}-${string}-${string}-${string}-${string}`;
Defined in: rxdb/dist/entity/EntityBase.d.ts:15
实体唯一标识符 自动生成的UUID,作为主键
Inherited from
remove()
remove: () => Promise<any>;
Defined in: rxdb/dist/entity/EntityBase.d.ts:81
删除
Returns
Promise<any>
Inherited from
reset()
reset: () => void;
Defined in: rxdb/dist/entity/EntityBase.d.ts:85
重置数据
Returns
void
Inherited from
save()
save: () => Promise<any>;
Defined in: rxdb/dist/entity/EntityBase.d.ts:89
保存
Returns
Promise<any>
Inherited from
updatedAt
readonly updatedAt: Date;
Defined in: rxdb/dist/entity/EntityBase.d.ts:25
更新时间 实体创建或更新时自动设置为当前时间
Inherited from
updatedBy?
readonly optional updatedBy: `${string}-${string}-${string}-${string}-${string}` | null;
Defined in: rxdb/dist/entity/EntityBase.d.ts:35
更新者ID 记录最后更新此实体的用户ID
Inherited from
addEdge()
static addEdge: <T>(this, from, to, weight?, properties?) => Promise<void>;
Defined in: rxdb-plugin-graph/src/GraphEntityBase.ts:106
添加边
Type Parameters
| Type Parameter |
|---|
T extends GraphEntityBase |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | () => T | - |
from | T | 起始节点 |
to | T | 目标节点 |
weight? | number | 边权重(可选) |
properties? | Record<string, any> | 边属性(可选) |
Returns
Promise<void>
Example
const userA = new User();
const userB = new User();
await User.addEdge(userA, userB, 8, { category: 'colleague' });
count()
static count: <T>(this, options) => Observable<number>;
Defined in: rxdb/dist/entity/EntityBase.d.ts:77
查询实体数量
Type Parameters
| Type Parameter |
|---|
T extends EntityBase |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | () => T | - |
options | CountOptions<() => T> | 查询选项,包含 where 条件 |
Returns
Observable<number>
Observable 包装的数量
Inherited from
countNeighbors()
static countNeighbors: <T, U>(this, options) => Observable<number>;
Defined in: rxdb-plugin-graph/src/GraphEntityBase.ts:62
统计邻居节点数量
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends GraphEntityBase | - |
U extends object | object |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | () => T | - |
options | FindNeighborsOptions<() => T, any, U> | 邻居查询选项 |
Returns
Observable<number>
Observable 包装的邻居数量
Example
// 统计好友数量
User.countNeighbors({ entityId: 'user1', level: 1 }).subscribe(count => {
console.log(`好友数: ${count}`);
});
find()
static find: <T>(this, options) => Observable<T[]>;
Defined in: rxdb/dist/entity/EntityBase.d.ts:59
查询多个实体
Type Parameters
| Type Parameter |
|---|
T extends EntityBase |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | () => T | - |
options | FindOptions<() => T> | 查询选项,包含 where 条件、limit、offset 等 |
Returns
Observable<T[]>
Observable 包装的实体实例数组
Inherited from
findAll()
static findAll: <T>(this, options) => Observable<T[]>;
Defined in: rxdb/dist/entity/EntityBase.d.ts:65
查询所有实体
Type Parameters
| Type Parameter |
|---|
T extends EntityBase |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | () => T | - |
options | FindAllOptions<() => T> | 查询选项,包含 where 条件和排序(不限制数量) |
Returns
Observable<T[]>
Observable 包装的实体实例数组
Inherited from
findByCursor()
static findByCursor: <T>(this, options) => Observable<T[]>;
Defined in: rxdb/dist/entity/EntityBase.d.ts:71
通过游标进行分页查询
Type Parameters
| Type Parameter |
|---|
T extends EntityBase |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | () => T | - |
options | FindByCursorOptions<() => T> | 游标分页选项,包含 orderBy、before/after 游标 |
Returns
Observable<T[]>
Observable 包装的实体实例数组
Inherited from
findNeighbors()
static findNeighbors: <T, U>(this, options) => Observable<NeighborResult<() => T, any>[]>;
Defined in: rxdb-plugin-graph/src/GraphEntityBase.ts:43
查询邻居节点(带边信息)
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends GraphEntityBase | - |
U extends object | object |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | () => T | - |
options | FindNeighborsOptions<() => T, any, U> | 邻居查询选项,包含起始节点、方向、跳数等 |
Returns
Observable<NeighborResult<() => T, any>[]>
Observable 包装的邻居结果数组
Example
// 查询直接好友
User.findNeighbors({ entityId: 'user1', level: 1 }).subscribe(neighbors => {
neighbors.forEach(n => {
console.log(n.node.name, n.edge.weight, n.level);
});
});
findOne()
static findOne: <T>(this, options) => Observable<T | null>;
Defined in: rxdb/dist/entity/EntityBase.d.ts:47
查找一个实体
Type Parameters
| Type Parameter |
|---|
T extends EntityBase |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | () => T | - |
options | FindOneOptions<() => T> | 查询选项,包含 where 条件 |
Returns
Observable<T | null>
Observable 包装的实体实例或 null
Inherited from
findOneOrFail()
static findOneOrFail: <T>(this, options) => Observable<T>;
Defined in: rxdb/dist/entity/EntityBase.d.ts:53
查找一个实体,查不到就抛出错误
Type Parameters
| Type Parameter |
|---|
T extends EntityBase |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | () => T | - |
options | FindOneOrFailOptions<() => T> | 查询选项,包含 where 条件 |
Returns
Observable<T>
Observable 包装的实体实例
Inherited from
findPaths()
static findPaths: <T, U>(this, options) => Observable<GraphPath<() => T>[]>;
Defined in: rxdb-plugin-graph/src/GraphEntityBase.ts:86
查询两个节点之间的所有路径
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends GraphEntityBase | - |
U extends object | object |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | () => T | - |
options | FindPathsOptions<() => T, any, U> | 路径查询选项,包含起点、终点、深度限制等 |
Returns
Observable<GraphPath<() => T>[]>
Observable 包装的路径数组
Example
// 查找城市间的路径
City.findPaths({
fromId: 'beijing',
toId: 'shanghai',
maxDepth: 5
}).subscribe(paths => {
paths[0].nodes.forEach(city => console.log(city.name));
console.log(`路径长度: ${paths[0].length}`);
});
get()
static get: <T>(this, id) => Observable<T>;
Defined in: rxdb/dist/entity/EntityBase.d.ts:41
根据 id 获取实体
Type Parameters
| Type Parameter |
|---|
T extends EntityBase |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | () => T | - |
id | `${string}-${string}-${string}-${string}-${string}` | 实体的唯一标识符 |
Returns
Observable<T>
Observable 包装的实体实例
Inherited from
removeEdge()
static removeEdge: <T>(this, from, to) => Promise<void>;
Defined in: rxdb-plugin-graph/src/GraphEntityBase.ts:125
移除边
Type Parameters
| Type Parameter |
|---|
T extends GraphEntityBase |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | () => T | - |
from | T | 起始节点 |
to | T | 目标节点 |
Returns
Promise<void>
Example
await User.removeEdge(userA, userB);