
因此,在过去的几天里,我一直在努力使RxDB工作,用命令启动了一个新的项目,使用的是角cli。
ng new <Projectname>在那之后
npm install rxdb然后,我在RxDB示例中创建了一个服务,我在这一行中遇到了问题。
export class DatabaseService {
static db$: Observable<RxDatabase> = Observable.fromPromise(RxDB
.create('collectionD', adapters[useAdapter], 'myLongAndStupidPassword', true)
.then(db => {
console.log('created Database');
window['db'] = db;
db.waitForLeadership()
.then(() => {
console.log('isLeader Now');
document.title = '♛ ' + document.title;
});
console.log('DatabaseService: create Collections');
const fns = collections
.map(col => db.collection(col.name, col.schema));
return Promise.all(fns)
.then((cols) => {
collections.map(col => col.dbCol = cols.shift());
return db;
});
})
// hooks
.then( db => {
db.collections.hero.preInsert( docObj => {
const color = docObj.color;
return db.collections.hero.findOne( {color} ).exec()
.then( has => {
if ( has != null ) {
alert( 'another hero already has the color ' + color );
throw new Error( 'color already there' );
}
return db;
});
});
})
.then( db => {
console.log('created collections');
return db;
})
)当我试图和webpack一起运行时,我会遇到这个错误。
ERROR in G:/projects/src/app/services/database.service.ts (28,62): Argument of type 'Promise<void>' is not assignable to parameter of type 'Promise<any>'. Property '[Symbol.toStringTag]' is missing in type 'Promise<void>'.)第28行是我按照RxDB文档给出的示例
static db$: Observable<RxDatabase> = Observable.fromPromise(RxDB
.create('collectionD', adapters[useAdapter], 'myLongAndStupidPassword', true)Vscode和ng服务都会产生相同的错误。
发布于 2017-02-27 08:56:37
多亏了你发送的链接,我成功地让RxDB开始工作。
到目前为止,这是我的密码。它创建一个DB和一个集合:
import {Component} from '@angular/core';
const _Promise = Promise;
const RxDB = require('rxdb');
RxDB.plugin(require('pouchdb-adapter-websql'));
Promise = _Promise;
const heroSchema = { ... };
@Component({
selector: 'rxdb',
template: `RxdbComponent`
})
export class RxdbComponent {
constructor() {
RxdbComponent.createDb()
.then(db => RxdbComponent.createCollection(db))
.then(coll => console.log(coll));
}
static createDb() {
return RxDB.create('tempDB', 'websql');
}
static createCollection(db: any) {
return db.collection('users', heroSchema);
}
}你能解释一下你想在你的db$中包装什么可以观察到吗?是数据库实例吗?收藏品?
可观测值是用来发出值的,我并不认为将db实例或集合包装在可观测范围内的意义(好吧,对于集合来说,这是有意义的,但是RxDB已经支持将查询公开为可观察的本地查询)。
https://stackoverflow.com/questions/42463877
复制相似问题