本文整理匯總了TypeScript中typestore.Coordinator.getRepo方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Coordinator.getRepo方法的具體用法?TypeScript Coordinator.getRepo怎麽用?TypeScript Coordinator.getRepo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類typestore.Coordinator
的用法示例。
在下文中一共展示了Coordinator.getRepo方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('#puts', async() => {
const
model = new Fixtures.PDBModel1(),
repo = coordinator.getRepo(Fixtures.PDBRepo1)
Object.assign(model, {
id: uuid.v4(),
createdAt: Faker.date.past(),
randomText: Faker.lorem.words(10)
})
const
savedModel = await repo.save(model),
key = repo.key(model.id)
// Check we got a doc value
expect((savedModel as any).$$doc).not.toBe(null)
let
modelGet = await repo.get(key)
expect(modelGet.id).toBe(model.id)
expect(modelGet.randomText).toBe(model.randomText)
let currentCount = await repo.count()
expect(currentCount).toBe(1)
await repo.remove(key)
expect(await repo.count()).toBe(0)
})
示例2: async
doTest = async (modelClazz,repoClazz) => {
try {
let
model = new modelClazz(),
repo = coordinator.getRepo(repoClazz)
Object.assign(model, {
id: uuid.v4(),
createdAt: Faker.date.past(),
randomText: Faker.lorem.words(10)
})
model = await repo.save(model)
const
model2 = Object.assign(new modelClazz(),model, {
randomText: Faker.lorem.words(10),
$$doc: Object.assign({},(model as any).$$doc,{
_rev: '1-aa86c0e405a07fb76ef3e523dd1c2ae1'
}),
})
await repo.save(model2)
return null
} catch (anErr) {
return anErr
}
}
示例3: runCars
export async function runCars() {
const idbOpts = {
databaseName: 'cars-db'
}
const dbToDelete = new Dexie(idbOpts.databaseName)
await dbToDelete.delete()
const idbStore = new IndexedDBPlugin(idbOpts, Car)
// Create a coordinator
const coordinator = new Coordinator()
// Initialize it with all plugins
await coordinator.init({
syncStrategy: SyncStrategy.Overwrite
},idbStore)
// Then start it with all models
await coordinator.start(Car)
let car1 = new Car({
manufacturer: 'volvo',
year: 1956,
model: '740gle',
tagLine: 'old school'
})
const repo1 = coordinator.getRepo(CarRepo)
car1 = await repo1.save(car1)
log.info('Car saved')
let carCount = await repo1.count()
assert(carCount === 1, 'only 1 car in there today!')
log.info('Car count = 1')
const car1Key = repo1.key(car1.manufacturer)
const car1FromRepo = await repo1.get(car1Key)
assert(car1FromRepo.manufacturer === car1.manufacturer &&
car1FromRepo.year === car1.year &&
car1FromRepo.model === car1.model
,`These should be identical\n${JSON.stringify(car1,null,4)}
from repo \n${JSON.stringify(car1FromRepo,null,4)}`)
log.info('Car models match')
await repo1.remove(car1Key)
log.info('Car removed')
carCount = await repo1.count()
assert(carCount === 0, 'only 1 car in there today!')
log.info('Car count 0')
log.info('All tests run')
return true
}
示例4: before
before(async () => {
t1 = new Fixtures.Test1()
t1.id = uuid()
t1.createdAt = new Date().getTime()
t1.randomText = 'asdfasdfadsf'
await coordinator.start(Fixtures.Test1)
test1Repo = coordinator.getRepo(Fixtures.Test1Repo)
})
示例5: it
it('#finder-fn',async () => {
const repo = coordinator.getRepo(Fixtures.IDBRepo1)
const models = []
const name = 'hello',
name2 = `${name} ${name}`
for (let x = 0; x < 10;x++) {
const model = new Fixtures.IDBModel1()
Object.assign(model,{
id: uuid.v4(),
name,
createdAt: Faker.date.past(),
randomText: Faker.lorem.words(10)
})
models.push(model)
}
await repo.bulkSave(...models)
let results = await repo.findByName(name)
expect(results.length).toBe(models.length)
// Testing second batch to make sure not all
const models2 = []
for (let x = 0; x < 20;x++) {
const model = new Fixtures.IDBModel1()
Object.assign(model,{
id: uuid.v4(),
name: name2,
createdAt: Faker.date.past(),
randomText: Faker.lorem.words(10)
})
models2.push(model)
}
await repo.bulkSave(...models2)
const results2 = await repo.findByName(name2)
expect(results2.length).toBe(models2.length)
// Test name 1 again to confirm
results = await repo.findByName(name)
expect(results.length).toBe(models.length)
const keys = models.concat(models2).map(result => repo.key(result.id))
await repo.bulkRemove(...keys)
expect(await repo.count()).toBe(0)
})
示例6: it
it('#remove', () => {
let repo = coordinator.getRepo(CloudSearchTest1Repo)
const stub = sinon.stub(repo, 'remove', function (o) {
log.info('Fake remove object', o)
expect(o.id).toBe(t1.id)
return this.index(IndexAction.Remove, o)
})
//const mock = sinon.mock(repo)
//mock.expects('remove').once()
return repo.remove(t1) //.then(() => mock.verify())
})