0
我想從node.js postgres sql中刪除一個名爲test
的數據庫,但它不起作用。如何使用node.js在postgres sql中刪除數據庫?
var express = require('express');
var app = express();
var pg = require('pg');
var pgp = require('pg-promise')();
// Connect to PostgreSQL database
var connectionString = process.env.DATABASE_URL || 'postgres://postgres:[email protected]:5432/test';
var db = pgp(connectionString);
db.connect();
db.query("DROP DATABASE test").then(function()
{
//createDatabases(db);
}).catch(function(err)
{
console.log(err);
});
但我得到一個錯誤
{ [error: cannot drop the currently open database]
name: 'error',
length: 87,
severity: 'ERROR',
code: '55006',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'dbcommands.c',
line: '834',
routine: 'dropdb' }
有誰知道如何解決它?
謝謝
你不應該叫'db.connect();'那裏。你不應該在那裏包含'pg'。 –