小编Car*_*ini的帖子

无法确定名为 的参数的 GraphQL 输入类型

我有两个相关模型:

1.- 角色实体

import { Column, Entity, BaseEntity, OneToMany, PrimaryColumn } from "typeorm";
import { Field, ObjectType } from "type-graphql";

import { UserEntity } from "./user.entity";


@ObjectType()
@Entity({
    name: "tb_roles"
})
export class RoleEntity extends BaseEntity {

    @Field()
    @PrimaryColumn({
        name: "id",
        type: "character varying",
        length: 5
    })
    id!: string;

    @Field()
    @Column({
        name: "description",
        type: "character varying",
        nullable: true
    })
    description!: string

    @Field(() => [UserEntity])
    @OneToMany(() => UserEntity, user => user.role)
    users!: UserEntity[];
}
Run Code Online (Sandbox Code Playgroud)

2.- 用户实体

import {Field, ObjectType} from "type-graphql"; …
Run Code Online (Sandbox Code Playgroud)

typescript graphql typeorm typegraphql

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

TypeORM - 重复键值违规

假设我有一个像这样的简单 TypeORM 实体:

import { Entity, PrimaryGeneratorColumn, Column } from 'typeorm';

@Entity()
export class Employee {
    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    Name: string;
}
Run Code Online (Sandbox Code Playgroud)

只要我不手动接触数据库,一切都可以正常工作。如果我手动输入记录,实体将无法检查id表中的最后一个当前记录并抛出 error duplicate key value violates unique constraint

例如:

  1. Employee Entity自己创建两条记录。
  2. 我的数据库中有两条记录,最后一条记录有id 2
  3. 我在数据库中手动创建第三条记录,它有id 3
  4. 之后,当Employee Entity运行时,它不会 = 创建另一个记录,因为它想使用id 3,但我已经手动添加了。
  5. 我收到错误duplicate key value violates unique constraint
  6. Employee Entity再次运行时,它会起作用,因为它尝试在已经可用的情况下保存另一条记录id 4

那么我如何确保检查Employee Entity数据库中的最后一个 id,然后使用增量保存下一条记录id

谢谢

orm typeorm nestjs

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

JQ 中的样本标准差

我有一个数字数组,我需要使用计算样本标准差jq

\n

标准差公式示例(学分):\n标准差公式

\n

我尝试将代码拆分为多个部分(长度、平均值),但我的尝试均无效,因为我不知道如何将所有数据合并为单个sqrtandmap操作:

\n
# Example of data input\n_data="[73,73,76,77,81,100]"\n\n_length=$(echo "$_data" | jq --raw-output \'length\')\n_mean=$(echo "$_data" | jq --raw-output \'add/length\')\n\n_standard_deviation=$(echo "$_data" \\\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 | jq --raw-output \\\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0  --arg length "$_length" \\\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0--arg mean "$_mean" \\\n\xc2\xa0 \xc2\xa0 \xc2\xa0 …
Run Code Online (Sandbox Code Playgroud)

json standard-deviation jq

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

从 Typescript 中的对象中删除 null 属性

作为参考从 Javascript 中的对象中删除空白属性,如何使其兼容 Typescript?

JS 函数(嵌套对象 | ES10):

function removeEmpty(obj) {
  return Object.fromEntries(
    Object.entries(obj)
      .filter(([_, v]) => v != null)
      .map(([k, v]) => [k, v === Object(v) ? removeEmpty(v) : v])
  );
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试过Exclude<T, null>,但它不适用于嵌套对象,并且我认为这不是正确的实用程序。

请注意,返回的类型应删除null类型但保留undefined

示例/预期行为:

type TestType = {
  a?: {
    b?: {
      c: string;
    } | null;
    z?: {
      x: string;
    };
  } | null;
};

const testObj: TestType = {
  a: {
    b: null,
    z: { …
Run Code Online (Sandbox Code Playgroud)

javascript null undefined typescript

3
推荐指数
1
解决办法
4654
查看次数