@_lukepatrick/postgraphile-upsert-plugin 中文文档教程

发布于 5年前 浏览 19 项目主页 更新于 3年前

postgraphile-upsert-plugin

将 postgres upsert 突变添加到 postgraphile

JavaScript 风格指南semantic-releaseGreenkeeper 徽章CircleCI

Getting Started

Install

yarn add @fullstackio/postgraphile-upsert-plugin

CLI

postgraphile --append-plugins @fullstackio/postgraphile-upsert-plugin:PgMutationUpsertPlugin

此处 有关使用 PostGraphile 加载插件的更多信息。

Library

const express = require("express");
const { postgraphile } = require("postgraphile");
const {
  PgMutationUpsertPlugin
} = require("@fullstackio/postgraphile-upsert-plugin");

const app = express();

app.use(
  postgraphile(pgConfig, schema, {
    appendPlugins: [PgMutationUpsertPlugin]
  })
);

app.listen(5000);

Usage

此插件使用 where 子句创建对 upsert 的添加操作,这是对表的任何唯一约束。 支持多列唯一索引。

Example

create table bikes (
  id serial PRIMARY KEY,
  "serialNumber" varchar UNIQUE NOT NULL,
  weight real,
  make varchar,
  model varchar
)

upsert 看起来像这样:

mutation {
  upsertBike(
    where: { serialNumber: "abc123" }
    input: {
      bike: {
        serialNumber: "abc123"
        weight: 25.6
        make: "kona"
        model: "cool-ie deluxe"
      }
    }
  ) {
    clientMutationId
  }
}

Credits

postgraphile-upsert-plugin

Add postgres upsert mutations to postgraphile.

JavaScript Style Guidesemantic-releaseGreenkeeper badgeCircleCI

Getting Started

Install

yarn add @fullstackio/postgraphile-upsert-plugin

CLI

postgraphile --append-plugins @fullstackio/postgraphile-upsert-plugin:PgMutationUpsertPlugin

See here for more information about loading plugins with PostGraphile.

Library

const express = require("express");
const { postgraphile } = require("postgraphile");
const {
  PgMutationUpsertPlugin
} = require("@fullstackio/postgraphile-upsert-plugin");

const app = express();

app.use(
  postgraphile(pgConfig, schema, {
    appendPlugins: [PgMutationUpsertPlugin]
  })
);

app.listen(5000);

Usage

This plugin creates an addition operation to upsert<Table> using a where clause, which is any unique constraint on the table. Supports multi-column unique indexes.

Example

create table bikes (
  id serial PRIMARY KEY,
  "serialNumber" varchar UNIQUE NOT NULL,
  weight real,
  make varchar,
  model varchar
)

An upsert would look like this:

mutation {
  upsertBike(
    where: { serialNumber: "abc123" }
    input: {
      bike: {
        serialNumber: "abc123"
        weight: 25.6
        make: "kona"
        model: "cool-ie deluxe"
      }
    }
  ) {
    clientMutationId
  }
}

Credits

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文