GraphRepository<T, U, V, RepositoryType>
Defined in: rxdb-plugin-graph/src/GraphRepository.ts:25
图结构实体仓库 提供图查询能力:邻居节点查询、路径查询等
Extends
Repository<T,RepositoryType>
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends EntityType & (...args) => IGraphEntity | - |
U extends EdgeFilterOptions | EdgeFilterOptionsFull |
V | EdgeInfoFull |
RepositoryType extends IGraphRepository<T, U, V> | IGraphRepository<T, U, V> |
Constructors
Constructor
new GraphRepository<T, U, V, RepositoryType>(rxdb, EntityType): GraphRepository<T, U, V, RepositoryType>;
Defined in: rxdb/dist/repository/Repository.d.ts:37
Parameters
| Parameter | Type |
|---|---|
rxdb | RxDB |
EntityType | T |
Returns
GraphRepository<T, U, V, RepositoryType>
Inherited from
Properties
_setLocal()
protected _setLocal: (entity) => void;
Defined in: rxdb/dist/repository/Repository.d.ts:93
设置状态 local
Parameters
| Parameter | Type |
|---|---|
entity | InstanceType<T> |
Returns
void
Inherited from
_setLocals()
protected _setLocals: (entities) => void;
Defined in: rxdb/dist/repository/Repository.d.ts:94
Parameters
| Parameter | Type |
|---|---|
entities | InstanceType<T>[] |
Returns
void
Inherited from
EntityType
readonly EntityType: T;
Defined in: rxdb/dist/repository/RepositoryBase.d.ts:9
Inherited from
local$
protected readonly local$: Observable<RepositoryType>;
Defined in: rxdb/dist/repository/Repository.d.ts:18
本地仓库
Inherited from
primary$
protected readonly primary$: Observable<RepositoryType>;
Defined in: rxdb/dist/repository/Repository.d.ts:28
主仓库(根据 SyncOptions 选择 local 或 remote)
- SyncType.None + 只有 remote:使用 remote$
- 其他情况:使用 local$
Inherited from
queryManager
protected readonly queryManager: QueryManager<T>;
Defined in: rxdb/dist/repository/Repository.d.ts:32
查询缓存管理器
Inherited from
remote$
protected readonly remote$: Observable<IRepository<T>>;
Defined in: rxdb/dist/repository/Repository.d.ts:22
远程仓库
Inherited from
rxdb
protected readonly rxdb: RxDB;
Defined in: rxdb/dist/repository/RepositoryBase.d.ts:8
Inherited from
sync
readonly sync: SyncOptions;
Defined in: rxdb/dist/repository/Repository.d.ts:36
同步配置
Inherited from
_STATIC_METHODS
protected static _STATIC_METHODS: string[];
Defined in: rxdb-plugin-graph/src/GraphRepository.ts:31
Overrides
Accessors
staticMethods
Get Signature
get static staticMethods(): string[];
Defined in: rxdb/dist/repository/RepositoryBase.d.ts:11
Returns
string[]
Inherited from
Methods
addEdge()
addEdge(
from,
to,
weight?,
properties?): Promise<void>;
Defined in: rxdb-plugin-graph/src/GraphRepository.ts:116
添加边
Parameters
| Parameter | Type |
|---|---|
from | InstanceType<T> |
to | InstanceType<T> |
weight? | number |
properties? | Record<string, any> |
Returns
Promise<void>
count()
count(options): Observable<number>;
Defined in: rxdb/dist/repository/Repository.d.ts:73
查询实体数量
Parameters
| Parameter | Type | Description |
|---|---|---|
options | CountOptions<T> | 查询选项,包含 where 条件 |
Returns
Observable<number>
Inherited from
countNeighbors()
countNeighbors(options): Promise<number>;
Defined in: rxdb-plugin-graph/src/GraphRepository.ts:80
查询邻居节点数量
Parameters
| Parameter | Type |
|---|---|
options | FindNeighborsOptions<T, any, U> |
Returns
Promise<number>
Remarks
- 指定 entityId 时:不包含起始节点,只统计邻居数量
- 统计规则与 findNeighbors 一致
Example
// 统计好友数量
const friendCount = await repo.countNeighbors({ entityId: 'alice-id', level: 1 });
create()
create(entity): Promise<InstanceType<T>>;
Defined in: rxdb/dist/repository/Repository.d.ts:78
创建实体
Parameters
| Parameter | Type | Description |
|---|---|---|
entity | InstanceType<T> | 要创建的实体实例 |
Returns
Promise<InstanceType<T>>
Inherited from
createEntityRef()
createEntityRef(data): any;
Defined in: rxdb/dist/repository/RepositoryBase.d.ts:17
获取实体实例
Parameters
| Parameter | Type | Description |
|---|---|---|
data | EntityUpdateData<T> | 实体数据 |
Returns
any
Inherited from
find()
find(options): Observable<InstanceType<T>[]>;
Defined in: rxdb/dist/repository/Repository.d.ts:57
查询多个实体
Parameters
| Parameter | Type | Description |
|---|---|---|
options | FindOptions<T> | 查询选项,包含 where 条件、limit、offset 等 |
Returns
Observable<InstanceType<T>[]>
Inherited from
findAll()
findAll(options): Observable<InstanceType<T>[]>;
Defined in: rxdb/dist/repository/Repository.d.ts:63
查询所有实体
Parameters
| Parameter | Type | Description |
|---|---|---|
options | FindAllOptions<T> | 查询选项,包含 where 条件和排序(不限制数量) |
Returns
Observable<InstanceType<T>[]>
Inherited from
findByCursor()
findByCursor(options): Observable<InstanceType<T>[]>;
Defined in: rxdb/dist/repository/Repository.d.ts:68
通过游标进行分页查询
Parameters
| Parameter | Type | Description |
|---|---|---|
options | FindByCursorOptions<T> | 游标分页选项,包含 orderBy、before/after 游标 |
Returns
Observable<InstanceType<T>[]>
Inherited from
findNeighbors()
findNeighbors(options): Promise<NeighborResult<T, V>[]>;
Defined in: rxdb-plugin-graph/src/GraphRepository.ts:54
查询邻居节点
Parameters
| Parameter | Type |
|---|---|
options | FindNeighborsOptions<T, any, U> |
Returns
Promise<NeighborResult<T, V>[]>
Remarks
- 指定 entityId 时:根据 level 返回 N 跳邻居
- direction 控制查询方向(入边/出边/双向)
- 结果包含起始节点(level=0 时)
Example
// 查询直接好友
const friends = await repo.findNeighbors({ entityId: 'alice-id', level: 1 });
findOne()
findOne(options): Observable<InstanceType<T> | null>;
Defined in: rxdb/dist/repository/Repository.d.ts:47
查找一个实体
Parameters
| Parameter | Type | Description |
|---|---|---|
options | FindOneOptions<T> | 查询选项,包含 where 条件 |
Returns
Observable<InstanceType<T> | null>
Inherited from
findOneOrFail()
findOneOrFail(options): Observable<InstanceType<T>>;
Defined in: rxdb/dist/repository/Repository.d.ts:52
查找一个实体,查不到就抛出错误
Parameters
| Parameter | Type | Description |
|---|---|---|
options | FindOneOrFailOptions<T> | 查询选项,包含 where 条件 |
Returns
Observable<InstanceType<T>>
Inherited from
findPaths()
findPaths(options): Promise<GraphPath<T>[]>;
Defined in: rxdb-plugin-graph/src/GraphRepository.ts:100
查询两个节点之间的所有路径
Parameters
| Parameter | Type |
|---|---|
options | FindPathsOptions<T, any, U> |
Returns
Promise<GraphPath<T>[]>
Remarks
- 返回所有非循环路径(节点不重复)
- 排序规则:首先按路径长度升序,长度相同时按总权重升序(权重越小优先)
- maxDepth 限制搜索深度,防止指数级爆炸
Example
// 查询 Alice 到 Bob 的所有路径
const paths = await repo.findPaths({ fromId: 'alice-id', toId: 'bob-id', maxDepth: 5 });
get()
get(id): Observable<InstanceType<T>>;
Defined in: rxdb/dist/repository/Repository.d.ts:42
根据 id 获取实体
Parameters
| Parameter | Type | Description |
|---|---|---|
id | EntityStaticType<T, "idType"> | 实体的唯一标识符 |
Returns
Observable<InstanceType<T>>
Inherited from
getEntityRef()
getEntityRef(id): InstanceType<T> | undefined;
Defined in: rxdb/dist/repository/RepositoryBase.d.ts:22
获取实体实例
Parameters
| Parameter | Type | Description |
|---|---|---|
id | EntityStaticType<T, "idType"> | 实体的 ID |
Returns
InstanceType<T> | undefined
Inherited from
hasEntityRef()
hasEntityRef(id): boolean;
Defined in: rxdb/dist/repository/RepositoryBase.d.ts:27
获取实体实例
Parameters
| Parameter | Type | Description |
|---|---|---|
id | EntityStaticType<T, "idType"> | 实体的 ID |
Returns
boolean
Inherited from
remove()
remove(entity): Promise<InstanceType<T>>;
Defined in: rxdb/dist/repository/Repository.d.ts:89
删除实体
Parameters
| Parameter | Type | Description |
|---|---|---|
entity | InstanceType<T> | 要删除的实体实例 |
Returns
Promise<InstanceType<T>>
Inherited from
removeEdge()
removeEdge(from, to): Promise<void>;
Defined in: rxdb-plugin-graph/src/GraphRepository.ts:129
移除边
Parameters
| Parameter | Type |
|---|---|
from | InstanceType<T> |
to | InstanceType<T> |
Returns
Promise<void>
update()
update(entity, patch): Promise<InstanceType<T>>;
Defined in: rxdb/dist/repository/Repository.d.ts:84
更新实体
Parameters
| Parameter | Type | Description |
|---|---|---|
entity | InstanceType<T> | 要更新的实体实例 |
patch | Partial<InstanceType<T>> | 部分更新数据 |
Returns
Promise<InstanceType<T>>
Inherited from
updateEntity()
updateEntity(entity, update): void;
Defined in: rxdb/dist/repository/RepositoryBase.d.ts:31
更新实体
Parameters
| Parameter | Type |
|---|---|
entity | InstanceType<T> |
update | InstanceType<T> |
Returns
void