getSyncType()
function getSyncType(metadata, globalSync?): RepositorySyncType;
Defined in: packages/rxdb/src/sync-contract/sync-type-utils.ts:84
从 EntityMetadata 获取同步类型
Parameters
| Parameter | Type | Description |
|---|---|---|
metadata | EntityMetadata | 实体元数据 |
globalSync? | | SyncOptions | EntitySyncResolver | 全局同步配置(可选,作为回退);传实例解析器 rxdb.entitySync 时连同实例覆盖一起解析 |
Returns
同步类型
Example
// Full sync (双向同步)
const metadata = {
sync: {
type: SyncType.Full,
local: { adapter: 'sqlite' },
remote: `{ adapter: 'supabase' }`
}
};
getSyncType(metadata); // 'full'
// Remote only (只读远程)
const metadata = {
sync: {
type: SyncType.None,
remote: `{ adapter: 'supabase' }`
}
};
getSyncType(metadata); // 'remote'
// Local only (只本地)
const metadata = {
sync: {
type: SyncType.None,
local: `{ adapter: 'sqlite' }`
}
};
getSyncType(metadata); // 'local'
// No sync (系统表)
const metadata = { sync: undefined };
getSyncType(metadata); // 'none'
// 使用全局配置回退
const metadata = { sync: undefined };
const globalSync = { type: SyncType.Full, local: {...}, remote: {...} };
getSyncType(metadata, globalSync); // 'full'