小编Oro*_*dan的帖子

cassandra主键列不能被限制

我第一次在Web应用程序中使用Cassandra,我遇到了查询问题.这是我的标签:

CREATE TABLE vote (
    doodle_id uuid,
    user_id uuid,
    schedule_id uuid,
    vote int,
    PRIMARY KEY ((doodle_id), user_id, schedule_id)
);
Run Code Online (Sandbox Code Playgroud)

在每个请求中,我都指示我的分区键doodle_id.例如,我可以毫无问题地制作:

select * from vote where doodle_id = c4778a27-f2ca-4c96-8669-15dcbd5d34a7 and user_id = 97a7378a-e1bb-4586-ada1-177016405142;
Run Code Online (Sandbox Code Playgroud)

但是根据我的最后一个要求:

select * from vote where doodle_id = c4778a27-f2ca-4c96-8669-15dcbd5d34a7 and schedule_id = c37df0ad-f61d-463e-bdcc-a97586bea633;
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Bad Request: PRIMARY KEY column "schedule_id" cannot be restricted (preceding column "user_id" is either not restricted or by a non-EQ relation)
Run Code Online (Sandbox Code Playgroud)

我是Cassandra的新手,但如果我错了,请纠正我,在复合主键中,第一部分是PARTITION KEY,它必须允许Cassandra知道在哪里查找数据.然后其他部分是CLUSTERING KEY来排序数据.

但我仍然不明白为什么我的第一个请求正在运行而不是第二个请求?

如果有人能帮忙,那将是一件非常愉快的事情.

cql cassandra cqlsh

18
推荐指数
2
解决办法
2万
查看次数

在没有detectChanges的情况下测试observable会失败

我正在复制一些Angular文档的例子,以提高我对角度单元测试的理解,最后我在一个简单的测试用例中,当我无法弄清楚发生了什么.

这是我的app.component.ts文件,当我有一个方法"getQuote"从服务获得报价.

@Component({...})
export class AppComponent {
  errMsg: string;
  quote: Observable<string>;

  constructor (private twainService: TwainService) {}

  getQuote () {
    this.quote = this.twainService.getQuote().pipe(
      catchError(err => {
        this.errMsg = err;
        return of('...');
      })
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

然后,我创建了一个测试来验证我的errMsg道具是否正确更新,以防我从twainService.getQuote方法收到错误:

describe('AppComponent', () => {
  let fixture: ComponentFixture<AppComponent>;
  let component: AppComponent;

  let getQuoteSpy;

  beforeEach(async(() => {
    const twainService = jasmine.createSpyObj('TwainService', ['getQuote']);
    getQuoteSpy = twainService.getQuote.and.returnValue(of(testQuote));

    TestBed.configureTestingModule({
      declarations: [
        AppComponent
      ],
      providers: [
        { provide: TwainService, useValue: twainService }
      ]
    }).compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(AppComponent); …
Run Code Online (Sandbox Code Playgroud)

unit-testing asynchronous observable jasmine angular

10
推荐指数
1
解决办法
600
查看次数

比较Node.js中的两个uuids

我有一个问题,我无法通过网络上的研究找到任何答案.我在Node.js和Cassandra中处理Web应用程序.我目前正在研究通知系统,我必须比较两个uuids,以确保我不会向做出原始操作的人发送通知(这会激发通知).

问题是,当我比较两个应该是等于的uuids时,我总是得到一个假值.

以下是我目前正在处理的代码示例:

console.log('user_id :', user_id.user_id);
console.log("user id of the current user :", this.user_id);

console.log(user_id.user_id == this.user_id);
console.log(user_id.user_id === this.user_id);
Run Code Online (Sandbox Code Playgroud)

以下是结果的显示:

user_id : Uuid: 29f1227d-58dd-4ddb-b0fa-19b7fc02fbe8
user id of the current user : Uuid: 29f1227d-58dd-4ddb-b0fa-19b7fc02fbe8
false
false
user_id : Uuid: c8f9c196-2d63-4cf0-b388-f11bfb1a476b
user id of the current user : Uuid: 29f1227d-58dd-4ddb-b0fa-19b7fc02fbe8
false
false
Run Code Online (Sandbox Code Playgroud)

如你所见,第一个uuids应该是相同的.它们是使用nodejs cassandra驱动程序中的uuid库生成的.当我能够使用指定的uuid在我的Cassandra数据库上发出任何请求时,我不明白为什么我无法比较它们.

如果有人能帮助我,那将是一件非常愉快的事!

comparison uuid cassandra node.js

7
推荐指数
1
解决办法
1470
查看次数

在 Apollo Client 3 中合并非规范化数据时出现“缓存数据可能丢失”警告

我正在将使用 Apollo Client 的应用程序从 v2 升级到 v3,但找不到以下问题的正确解决方案。

我有一个产品的架构,在这个产品中,有一个价格。这个价格不是一个简单的数字,因为它包含免税价值、所有税金包括价值和增值税。

type Product {
   id: ID
   price: Price
}

type Price {
   dutyFree: Float
   allTaxesIncluded: Float
   VAT: Float
}
Run Code Online (Sandbox Code Playgroud)

在 Apollo Client 2 中,只要没有明确的 id 或 _id 属性,InMemoryCache 就会根据对象的路径创建回退假标识符来规范数据。

在 Apollo Client 3 中,不再生成此后备假标识符。相反,您有两种选择来处理非规范化数据。第一个是使用新的 TypePolicy 选项并明确指示您收到的数据不应标准化。在这种情况下,数据将链接到父规范化数据。

文档:

未规范化的对象会嵌入到缓存中的父对象中。您不能直接访问这些对象,但可以通过它们的父对象访问它们。

new InMemoryCache({
   typePolicies: {
      Price {
         keyFields: false
      }
   }
})
Run Code Online (Sandbox Code Playgroud)

都很开心,虽然我的问题解决了。好吧,错了......我可以在我的应用程序中创建一个产品并添加一个价格。但是,每当我更改现有价格时,都会收到以下警告:

替换 Product 对象的 price 字段时,缓存数据可能会丢失。

因为,当我在更新后获取我的 Product 时,InMemoryCache 不知道如何合并字段 Price 因为没有定义 id,这是非规范化数据的点。

我知道有第二个选项可以为我的 Product.price 字段显式定义合并函数,但这个例子是现实的一个更简单的版本。我通过多个类型为 Price 的对象有大量字段,并且为每个对象手动定义一个合并函数(即使通过外部化函数中的公共逻辑)是我发现效率非常低和错误的来源。

所以我的问题是:我对这个keyFields: false选项有什么误解,我可以做些什么来解决这个问题,而不必求助于在我的应用程序中为 50 多个字段定义合并函数? …

apollo apollo-client

7
推荐指数
1
解决办法
852
查看次数

async.waterfall绑定上下文

我目前正在使用node.js处理Web应用程序,我无法解决库异步的上下文问题.

这是我的应用程序的代码示例:

notification.prototype.save = function (callback) {

    async.parallel([
        // Save the notification and associate it with the doodle
        function _saveNotification (done) {

            var query = 'INSERT INTO notification (notification_id, user_id, doodle_id, schedule_id) values (?, ?, ?, ?)';
            notification.db.execute(query, [ this.notification_id, this.user_id, this.doodle_id, this.schedule_id ], { prepare : true }, function (err) {
                return done(err);
            });

            console.log("SAVE NOTIFICATION");
            console.log("doodle_id", this.doodle_id);

        }.bind(this),

        // Save notification for the users with the good profile configuration
        function _saveNotificationForUsers (done) {
            this.saveNotificationForUsers(done);
        }.bind(this)

    ], function (err) …
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous bind node.js

5
推荐指数
1
解决办法
3129
查看次数

Angular 2模板驱动表单组验证

我有一个关于角度2模板驱动形式的问题.我已经设置了这个表单中的一个,如果表单组中的一个输入无效,我希望能够向用户显示警告.

例如,假设我有以下形式:

<form class="form" #f="ngForm" (submit)="submit()">
    <div class="form-group">
       <input type="text" name="firstName" required [(ngModel)]="user.firstName">
       <input type="text" name="lastName" required [(ngModel)]="user.lastName">
    </div>
    <div class="form-group">
        <input type="text name="address" required [(ngModel)]="user.address">
    </div>
    <button type="submit" [disabled]="!f.valid">Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud)


如果firstName和/或lastName无效,我希望包含输入"firstName"和输入"lastName"的整个表单组更改.我知道我可以这样做:

<div class="form-group" [class.has-error]="!firstName.valid || !lastName.valid">
   <input type="text" name="firstName" required [(ngModel)]="user.firstName" #firstName="ngModel">
   <input type="text" name="lastName" required [(ngModel)]="user.lastName" #lastName="ngModel">
</div>
Run Code Online (Sandbox Code Playgroud)


它会工作得很好.但这里有一个棘手的部分:在这个例子中,我只有两个带有简单验证规则的输入,所以它很容易检查并且仍然可读.但是,如果我有10个输入来检查表单组怎么办?我不想最终必须手动检查每个输入的有效性.

我找到的解决方案之一是在第一个中创建一个子表单:

<form class="form" #f="ngForm" (submit)="submit()">
    <form #subForm="ngForm" [class.has-error]="!subForm.valid">
       <input type="text" name="firstName" required [(ngModel)]="user.firstName">
       <input type="text" name="lastName" required [(ngModel)]="user.lastName">
    </form>
    <div class="form-group">
        <input type="text name="address" required [(ngModel)]="user.address">
    </div>
    <button type="submit" …
Run Code Online (Sandbox Code Playgroud)

javascript forms validation angular

5
推荐指数
1
解决办法
4537
查看次数

是的,如何验证空对象上的必填字段

我在验证强制字段时遇到问题,这些字段是(可能)空对象的属性。

这是一个示例架构:

object().shape({
   catalog: {
      brand: string().required()
   }
})
Run Code Online (Sandbox Code Playgroud)

如果我尝试根据此架构验证以下对象,我会收到预期的错误:需要品牌。据我了解,为未定义的对象创建了一个默认值,它模仿了模式中对象的形状。这是我所期望的行为,也是我想要的。

{ catalog: undefined }

// "catalog.brand is a required field"
Run Code Online (Sandbox Code Playgroud)

但就我而言,我没有收到未定义的对象,而是收到 null 的对象。我不知道如何使用空值来管理相同的结果。

{ catalog: null }

// No error on catalog.brand
Run Code Online (Sandbox Code Playgroud)

手动将 null 转换为 undefined 是不可能的,因为我收到 null 是有充分理由的。

这是一个 codeandbox,它重现了我的用例:

https://codesandbox.io/s/yup-playground-tbfcj

我真的很感激对此的帮助,谢谢:)

javascript validation yup

4
推荐指数
1
解决办法
1万
查看次数