簡體   English   中英

類型錯誤:response.json 不是函數

[英]TypeError: response.json is not a function

我想將我的查詢結果上傳到我的 postgresql 數據庫的 JSON 格式的 API。

但是我發現我的 json 尚未定義:

類型錯誤:response.json 不是函數

如何將這些數據上傳到銀行?

我想在 SQL 中以傳統方式上傳數據,而不是作為 JSON 字段,以便將來能夠進行查詢

索引.js

require('es6-promise').polyfill();
require('isomorphic-fetch');

let content = {

    "query": `{
                squads {
                    name
                        cards(includedOnKanban: true, closed: false, archived: false, cancelled: false, updatedSince: \"2020-01-01T00:00:00-0300\") {
                            identifier
                            title
                            description
                            status
                            priority

                            assignees {
                                fullname
                                email
                              }

                        }
                    }
            }`

};

fetch('https://www.bluesight.io/graphql', {
method: 'POST',
headers: {
    'Content-Type': 'application/json',
    'Bluesight-API-Token': 'token-here'
},
body: JSON.stringify(content)
})
.then(response => {
    if (response.ok) {
      return response.json()
    } else {
      return Promise.reject('something went wrong!')
    }
  })
.then(response => console.log(response.data))
.then(response => console.log(JSON.stringify(response.data)));

const { Client } = require('pg');

const client = new Client({
    user: 'postgres',
    host: '127.0.0.1',
    database: 'dbbase',
    password: 'postgres',
    port: 5432,
})
client.connect();
client.query('INSERT INTO tb_bluesight (identifier,title,description,status,priority,fullname,email,date_insert) VALUES ($1, $2, $3, $4, $5, $6, $7, current_timestamp)', response => response.json());
client.end();

JSON

{
    "data": {
        "squads": [
            {
                "name": "SUPPORT IT",
                "cards": [
                    {
                        "identifier": "06x38y",
                        "title": "ALL - Validate data,
                        "description": "review database.",
                        "status": null,
                        "priority": "medium",
                        "assignees": [
                            {
                                "fullname": "Carlos",
                                "email": "carlos@br.it.com",
                            }
                        ]
                    }
                ]
            }
        ]
    }
}

桌子

CREATE TABLE tb_bluesight(
identifier varchar,
title varchar,
description varchar,
status varchar,
priority varchar,
fullname varchar,
email varchar,
date_insert timestamp
);
const data = fetch('https://www.bluesight.io/graphql', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Bluesight-API-Token': 'token-here'
    },
    body: JSON.stringify(content)
})
.then(response => {
    if (response.ok) {
        return response.json()
    } else {
        return Promise.reject('something went wrong!')
    }
});

const { Client } = require('pg');

const client = new Client({
    user: 'postgres',
    host: '127.0.0.1',
    database: 'dbbase',
    password: 'postgres',
    port: 5432,
});

client.connect();

// Example, replace with real values
const parameters = ['$1', '$2', '$3', '$4','$5', '$6', '$7'];

const query = "INSERT INTO tb_bluesight 
 (identifier,title,description,status,priority,fullname,email,date_insert) 
     VALUES ($1, $2, $3, $4, $5, $6, $7, CURRENT_TIMESTAMP)";

client.query(query, parameters, (err, res) => {
    if (err) {
        console.log(err.stack)
    } else {
        // res.rows will contain the inserted rows
        console.log(res.rows[0])
    }
});

client.end();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM