跳到主要内容

GraphRepository<T, U, V, RepositoryType>

Defined in: rxdb-plugin-graph/src/GraphRepository.ts:25

图结构实体仓库 提供图查询能力:邻居节点查询、路径查询等

Extends

Type Parameters

Type ParameterDefault type
T extends EntityType & (...args) => IGraphEntity-
U extends EdgeFilterOptionsEdgeFilterOptionsFull
VEdgeInfoFull
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

ParameterType
rxdbRxDB
EntityTypeT

Returns

GraphRepository<T, U, V, RepositoryType>

Inherited from

Repository.constructor

Properties

_setLocal()

protected _setLocal: (entity) => void;

Defined in: rxdb/dist/repository/Repository.d.ts:93

设置状态 local

Parameters

ParameterType
entityInstanceType<T>

Returns

void

Inherited from

Repository._setLocal


_setLocals()

protected _setLocals: (entities) => void;

Defined in: rxdb/dist/repository/Repository.d.ts:94

Parameters

ParameterType
entitiesInstanceType<T>[]

Returns

void

Inherited from

Repository._setLocals


EntityType

readonly EntityType: T;

Defined in: rxdb/dist/repository/RepositoryBase.d.ts:9

Inherited from

Repository.EntityType


local$

protected readonly local$: Observable<RepositoryType>;

Defined in: rxdb/dist/repository/Repository.d.ts:18

本地仓库

Inherited from

Repository.local$


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

Repository.primary$


queryManager

protected readonly queryManager: QueryManager<T>;

Defined in: rxdb/dist/repository/Repository.d.ts:32

查询缓存管理器

Inherited from

Repository.queryManager


remote$

protected readonly remote$: Observable<IRepository<T>>;

Defined in: rxdb/dist/repository/Repository.d.ts:22

远程仓库

Inherited from

Repository.remote$


rxdb

protected readonly rxdb: RxDB;

Defined in: rxdb/dist/repository/RepositoryBase.d.ts:8

Inherited from

Repository.rxdb


sync

readonly sync: SyncOptions;

Defined in: rxdb/dist/repository/Repository.d.ts:36

同步配置

Inherited from

Repository.sync


_STATIC_METHODS

protected static _STATIC_METHODS: string[];

Defined in: rxdb-plugin-graph/src/GraphRepository.ts:31

Overrides

Repository._STATIC_METHODS

Accessors

staticMethods

Get Signature

get static staticMethods(): string[];

Defined in: rxdb/dist/repository/RepositoryBase.d.ts:11

Returns

string[]

Inherited from

Repository.staticMethods

Methods

addEdge()

addEdge(
from,
to,
weight?,
properties?): Promise<void>;

Defined in: rxdb-plugin-graph/src/GraphRepository.ts:116

添加边

Parameters

ParameterType
fromInstanceType<T>
toInstanceType<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

ParameterTypeDescription
optionsCountOptions<T>查询选项,包含 where 条件

Returns

Observable<number>

Inherited from

Repository.count


countNeighbors()

countNeighbors(options): Promise<number>;

Defined in: rxdb-plugin-graph/src/GraphRepository.ts:80

查询邻居节点数量

Parameters

ParameterType
optionsFindNeighborsOptions<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

ParameterTypeDescription
entityInstanceType<T>要创建的实体实例

Returns

Promise<InstanceType<T>>

Inherited from

Repository.create


createEntityRef()

createEntityRef(data): any;

Defined in: rxdb/dist/repository/RepositoryBase.d.ts:17

获取实体实例

Parameters

ParameterTypeDescription
dataEntityUpdateData<T>实体数据

Returns

any

Inherited from

Repository.createEntityRef


find()

find(options): Observable<InstanceType<T>[]>;

Defined in: rxdb/dist/repository/Repository.d.ts:57

查询多个实体

Parameters

ParameterTypeDescription
optionsFindOptions<T>查询选项,包含 where 条件、limit、offset 等

Returns

Observable<InstanceType<T>[]>

Inherited from

Repository.find


findAll()

findAll(options): Observable<InstanceType<T>[]>;

Defined in: rxdb/dist/repository/Repository.d.ts:63

查询所有实体

Parameters

ParameterTypeDescription
optionsFindAllOptions<T>查询选项,包含 where 条件和排序(不限制数量)

Returns

Observable<InstanceType<T>[]>

Inherited from

Repository.findAll


findByCursor()

findByCursor(options): Observable<InstanceType<T>[]>;

Defined in: rxdb/dist/repository/Repository.d.ts:68

通过游标进行分页查询

Parameters

ParameterTypeDescription
optionsFindByCursorOptions<T>游标分页选项,包含 orderBy、before/after 游标

Returns

Observable<InstanceType<T>[]>

Inherited from

Repository.findByCursor


findNeighbors()

findNeighbors(options): Promise<NeighborResult<T, V>[]>;

Defined in: rxdb-plugin-graph/src/GraphRepository.ts:54

查询邻居节点

Parameters

ParameterType
optionsFindNeighborsOptions<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

ParameterTypeDescription
optionsFindOneOptions<T>查询选项,包含 where 条件

Returns

Observable<InstanceType<T> | null>

Inherited from

Repository.findOne


findOneOrFail()

findOneOrFail(options): Observable<InstanceType<T>>;

Defined in: rxdb/dist/repository/Repository.d.ts:52

查找一个实体,查不到就抛出错误

Parameters

ParameterTypeDescription
optionsFindOneOrFailOptions<T>查询选项,包含 where 条件

Returns

Observable<InstanceType<T>>

Inherited from

Repository.findOneOrFail


findPaths()

findPaths(options): Promise<GraphPath<T>[]>;

Defined in: rxdb-plugin-graph/src/GraphRepository.ts:100

查询两个节点之间的所有路径

Parameters

ParameterType
optionsFindPathsOptions<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

ParameterTypeDescription
idEntityStaticType<T, "idType">实体的唯一标识符

Returns

Observable<InstanceType<T>>

Inherited from

Repository.get


getEntityRef()

getEntityRef(id): InstanceType<T> | undefined;

Defined in: rxdb/dist/repository/RepositoryBase.d.ts:22

获取实体实例

Parameters

ParameterTypeDescription
idEntityStaticType<T, "idType">实体的 ID

Returns

InstanceType<T> | undefined

Inherited from

Repository.getEntityRef


hasEntityRef()

hasEntityRef(id): boolean;

Defined in: rxdb/dist/repository/RepositoryBase.d.ts:27

获取实体实例

Parameters

ParameterTypeDescription
idEntityStaticType<T, "idType">实体的 ID

Returns

boolean

Inherited from

Repository.hasEntityRef


remove()

remove(entity): Promise<InstanceType<T>>;

Defined in: rxdb/dist/repository/Repository.d.ts:89

删除实体

Parameters

ParameterTypeDescription
entityInstanceType<T>要删除的实体实例

Returns

Promise<InstanceType<T>>

Inherited from

Repository.remove


removeEdge()

removeEdge(from, to): Promise<void>;

Defined in: rxdb-plugin-graph/src/GraphRepository.ts:129

移除边

Parameters

ParameterType
fromInstanceType<T>
toInstanceType<T>

Returns

Promise<void>


update()

update(entity, patch): Promise<InstanceType<T>>;

Defined in: rxdb/dist/repository/Repository.d.ts:84

更新实体

Parameters

ParameterTypeDescription
entityInstanceType<T>要更新的实体实例
patchPartial<InstanceType<T>>部分更新数据

Returns

Promise<InstanceType<T>>

Inherited from

Repository.update


updateEntity()

updateEntity(entity, update): void;

Defined in: rxdb/dist/repository/RepositoryBase.d.ts:31

更新实体

Parameters

ParameterType
entityInstanceType<T>
updateInstanceType<T>

Returns

void

Inherited from

Repository.updateEntity