GraphRepository<T, U, V, RepositoryType>
Defined in: rxdb-plugin-graph/src/GraphRepository.ts:33
图结构实体仓库 提供图查询能力:邻居节点查询、路径查询等
Extends
Repository<T,RepositoryType>
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends EntityType & (...args) => IGraphEntity | - |
U extends EdgeFilterOptions | EdgeFilterOptionsFull |
V | GraphEdgeInfoType<U> |
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-plugin-graph/src/GraphRepository.ts:51
Parameters
| Parameter | Type |
|---|---|
rxdb | RxDB |
EntityType | T |
Returns
GraphRepository<T, U, V, RepositoryType>
Overrides
Properties
_setLocal
protected _setLocal: (entity) => void;
Defined in: rxdb/dist/repository/Repository.d.ts:124
设置状态 local
Parameters
| Parameter | Type |
|---|---|
entity | InstanceType<T> |
Returns
void
Inherited from
_setLocals
protected _setLocals: (entities) => void;
Defined in: rxdb/dist/repository/Repository.d.ts:125
Parameters
| Parameter | Type |
|---|---|
entities | InstanceType<T>[] |
Returns
void
Inherited from
EntityType
readonly EntityType: T;
Defined in: rxdb/dist/repository/RepositoryBase.d.ts:20
Inherited from
local$
protected readonly local$: Observable<RepositoryType>;
Defined in: rxdb/dist/repository/Repository.d.ts:20
本地仓库
Inherited from
primary$
protected readonly primary$: Observable<RepositoryType>;
Defined in: rxdb/dist/repository/Repository.d.ts:30
主仓库(根据 SyncOptions 选择 local 或 remote)
- SyncType.None + 只有 remote:使用 remote$
- 其他情况:使用 local$
Inherited from
queryManager
protected readonly queryManager: QueryManager<T>;
Defined in: rxdb/dist/repository/Repository.d.ts:34
查询缓存管理器
Inherited from
remote$
protected readonly remote$: Observable<IRepository<T>>;
Defined in: rxdb/dist/repository/Repository.d.ts:24
远程仓库
Inherited from
rxdb
protected readonly rxdb: RxDB;
Defined in: rxdb/dist/repository/RepositoryBase.d.ts:19
Inherited from
sync
readonly sync: SyncOptions;
Defined in: rxdb/dist/repository/Repository.d.ts:42
本实例对该实体的生效同步配置(经 rxdb.entitySync.resolve 解析)
Remarks
只读:被 syncOverrides 覆盖的实体拿到的是实例冻结的快照,运行时改它的字段会抛 TypeError。
未覆盖实体这里恰好是装饰器或库级配置原对象,同样不要改 —— 其他实例也在读它。
Inherited from
_STATIC_METHODS
protected static _STATIC_METHODS: string[];
Defined in: rxdb-plugin-graph/src/GraphRepository.ts:39
子类声明的"静态方法名"清单,用于把 User.findOne(...) 这样的方法
注入到实体类上(EntityManager.init 时挂)。
Remarks
用类字段 static 而非构造器里赋值 —— 字段初始化在 extends 链上是自底向上
合并的,所以子类定义的 _STATIC_METHODS 不会丢;运行时反射取的是当前类的字段。
Overrides
Accessors
staticMethods
Get Signature
get static staticMethods(): string[];
Defined in: rxdb/dist/repository/RepositoryBase.d.ts:37
当前类(含继承链上各层)声明的全部静态方法名
Remarks
没有沿原型链累加:每个子类自己写一份 _STATIC_METHODS,避免运行时
反射出祖先的 get / findOne 这类名字后,再被后代意外覆盖一次。
Returns
string[]
Inherited from
Methods
addEdge()
addEdge(
from,
to,
weight?,
properties?
): Promise<void>;
Defined in: rxdb-plugin-graph/src/GraphRepository.ts:162
添加边
Parameters
| Parameter | Type |
|---|---|
from | InstanceType<T> |
to | InstanceType<T> |
weight? | number | null |
properties? | | GraphEdgeProperties<U> | null |
Returns
Promise<void>
count()
count(options): Observable<number>;
Defined in: rxdb/dist/repository/Repository.d.ts:97
查询实体数量
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:119
Parameters
| Parameter | Type |
|---|---|
options | FindNeighborsOptions<T, GraphWhere<T>, U> |
Returns
Promise<number>
countNeighbors$()
countNeighbors$(options): Observable<number>;
Defined in: rxdb-plugin-graph/src/GraphRepository.ts:113
查询邻居节点数量
Parameters
| Parameter | Type |
|---|---|
options | FindNeighborsOptions<T, GraphWhere<T>, U> |
Returns
Observable<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:102
创建实体
Parameters
| Parameter | Type | Description |
|---|---|---|
entity | InstanceType<T> | 要创建的实体实例 |
Returns
Promise<InstanceType<T>>
Inherited from
createEntityRef()
createEntityRef(data): EntityInstanceType<T>;
Defined in: rxdb/dist/repository/RepositoryBase.d.ts:50
创建(或复用)一个实体引用
Parameters
| Parameter | Type | Description |
|---|---|---|
data | EntityUpdateData<T> | 字段初始值;其中 id 缺省时会自动生成 |
Returns
已挂到 EntityManager 缓存里的实体实例
Remarks
不管入参 id 是否已存在于缓存,都会优先返回缓存里的实例(覆盖式刷新);
走 rxdb.entityManager.createEntityRef 是为了复用同一份引用语义,避免
不同调用栈里拿到的是两个状态不同步的克隆。
Inherited from
destroy()
destroy(): void;
Defined in: rxdb/dist/repository/Repository.d.ts:54
销毁本仓储:摘掉事件监听、清空同步记忆、关掉查询管理器。
Returns
void
Remarks
#queryCacheSession.clear() 不是顺手做的清理,而是释放资源:记忆表的每一条都挂着一个
setTimeout,窗口由 syncStaleTime 决定(可配成分钟级)。不清的话,断连时销毁的
仓储连同它的记忆闭包会被这些计时器钉在事件循环上直到窗口自己走完 —— Node / Electron
里这还会拖住进程退出。clear() 同时递增代次,销毁瞬间还在飞的同步回来时不会把
记忆写回一个已经死掉的仓储。
Inherited from
find()
find(options): Observable<InstanceType<T>[]>;
Defined in: rxdb/dist/repository/Repository.d.ts:74
查询多个实体
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:80
查询所有实体
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:92
通过游标进行分页查询
Parameters
| Parameter | Type | Description |
|---|---|---|
options | FindByCursorOptions<T> | 游标分页选项,包含 orderBy、before/after 游标 |
Returns
Observable<InstanceType<T>[]>
Remarks
before(反向翻页)需要反转排序后再查:limit 在 SQL 里永远从结果集开头截取,
保持调用方的正向排序就只会拿到整个集合最靠前的那一页,而不是紧挨游标之前的一页。
因此下发适配器时反转 orderBy,返回调用方之前再把数组还原成调用方要求的顺序 ——
增量合并(merge_create.ts 的 findByCursor 分支)也按 options.orderBy 排序后切片,
两侧必须同序。
Inherited from
findNeighbors()
findNeighbors(options): Promise<GraphQueryResult<NeighborResult<T, V>>>;
Defined in: rxdb-plugin-graph/src/GraphRepository.ts:96
Parameters
| Parameter | Type |
|---|---|
options | FindNeighborsOptions<T, GraphWhere<T>, U> |
Returns
Promise<GraphQueryResult<NeighborResult<T, V>>>
findNeighbors$()
findNeighbors$(options): Observable<GraphQueryResult<NeighborResult<T, V>>>;
Defined in: rxdb-plugin-graph/src/GraphRepository.ts:74
查询邻居节点
Parameters
| Parameter | Type |
|---|---|
options | FindNeighborsOptions<T, GraphWhere<T>, U> |
Returns
Observable<GraphQueryResult<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:64
查找一个实体
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:69
查找一个实体,查不到就抛出错误
Parameters
| Parameter | Type | Description |
|---|---|---|
options | FindOneOrFailOptions<T> | 查询选项,包含 where 条件 |
Returns
Observable<InstanceType<T>>
Inherited from
findPaths()
findPaths(options): Promise<GraphQueryResult<GraphPath<T>>>;
Defined in: rxdb-plugin-graph/src/GraphRepository.ts:155
Parameters
| Parameter | Type |
|---|---|
options | FindPathsOptions<T, GraphWhere<T>, U> |
Returns
Promise<GraphQueryResult<GraphPath<T>>>
findPaths$()
findPaths$(options): Observable<GraphQueryResult<GraphPath<T>>>;
Defined in: rxdb-plugin-graph/src/GraphRepository.ts:137
查询两个节点之间的所有路径
Parameters
| Parameter | Type |
|---|---|
options | FindPathsOptions<T, GraphWhere<T>, U> |
Returns
Observable<GraphQueryResult<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:59
根据 id 获取实体
Parameters
| Parameter | Type | Description |
|---|---|---|
id | EntityStaticType<T, "idType"> | 实体的唯一标识符 |
Returns
Observable<InstanceType<T>>
Inherited from
getEntityRef()
getEntityRef(id):
| EntityInstanceType<T>
| undefined;
Defined in: rxdb/dist/repository/RepositoryBase.d.ts:57
按 ID 在当前进程的实体缓存中查找实体
Parameters
| Parameter | Type | Description |
|---|---|---|
id | EntityStaticType<T, "idType"> | 实体主键 |
Returns
| EntityInstanceType<T>
| undefined
缓存命中则返回实例,未命中返回 undefined(不触发数据库查询)
Inherited from
hasEntityRef()
hasEntityRef(id): boolean;
Defined in: rxdb/dist/repository/RepositoryBase.d.ts:68
判定当前进程的实体缓存里是否有指定 ID
Parameters
| Parameter | Type | Description |
|---|---|---|
id | EntityStaticType<T, "idType"> | 实体主键 |
Returns
boolean
缓存命中返回 true,否则 false
Remarks
等价于 getEntityRef(id) !== undefined,单独提供是为了让"批量预热"和
"差异同步"等热点路径省掉一次引用创建 / 取状态的开销。
Inherited from
rawQuery()
protected rawQuery(sql, params?): Promise<RawQueryResult>;
Defined in: rxdb/dist/repository/Repository.d.ts:120
执行原始 SQL 查询 用于条件 UPDATE 等需要绕过 ORM 的场景
Parameters
| Parameter | Type | Description |
|---|---|---|
sql | string | SQL 语句 |
params? | unknown[] | 绑定参数 |
Returns
Promise<RawQueryResult>
Inherited from
remove()
remove(entity): Promise<InstanceType<T>>;
Defined in: rxdb/dist/repository/Repository.d.ts:113
删除实体
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:174
移除边
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:108
更新实体
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:80
用 update 覆盖实体字段
Parameters
| Parameter | Type | Description |
|---|---|---|
entity | InstanceType<T> | 目标实体 |
update | InstanceType<T> | 待写入的字段;主键 id 也会被赋值(用于 hydrate 场景) |
Returns
void
Remarks
走 EntityStatus.applyExternal,保证 dirty tracking 与 patch 生成走的是同一条路径,
且实体有未保存编辑时逐字段避让而不是整行覆盖 —— 活查询整批回填会命中已被用户改过的实体,
无条件 replace 会静默吃掉那些编辑。