問題タブ [node-postgres]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
json - ECONNREFUSED when making GET request in app, but API returns JSON successfully
I'm writing a node app with React, using node-postgres and superagent for backend calls. Let's say I'm making a GET request and using the JSON it returns to fill a table of students. My API looks like this:
On page load, this is called from the store to set a students array. It seems like something is going wrong here:
If I curl localhost:3000/api/getStudents
, I get the JSON response I expect.
However, when I call this on page load, I get an ECONNREFUSED error:
Not sure why I'm getting an error on the HTTP port. This is my first time using node-postgres, superagent, and React so any help is appreciated.
Edit: Forgot to mention that I'm able to make POST requests and insert items into the database without any errors. This error only occurs when I'm attempting a GET request.
node.js - From express + pg to reusable code : help refactoring
So, I have some node code to deal with and I’m hoping someone here can help me refactor it. This is express + pg:
I want to extract the part that runs the query, that is, basically everything inside the express controller action. Except of course, nested inside the callbacks, is express code. How would you refactor this?
node.js - AWS Lambda のノード関数が node-pg でデータベースに接続できない
関数はローカルで動作しますが、AWS Lambda にデプロイすると、postgres データベースに接続できないようです。エラーは次のとおりです。
私のデータベースは Azure 仮想マシンでホストされており、ローカルで実行されている場合、他のアプリからもこのアプリからも接続に問題はありません。Lambda での実行時に接続が失敗する原因は何ですか?
sql - このソケットは相手側によって終了されました] コード: 'EPIPE'
たとえば、挿入が成功してから約 10 秒後に、いくつかのアクションの後、このエラーが表示されます。
つまり、最初は問題なく挿入できますが、何か他のものを挿入したり、データを取得したりしようとすると、このエラーが発生します。
アイドル後は発生しません。いくつかのアクションの後のみ。場合によっては取得後に、常に挿入後に。
挿入クエリの例:
これが同じクエリです。読みやすくするために少しフォーマットしました。
node.js - node-postgres で done() をいつ呼び出す必要がありますか?
pg 4.4.3
クライアント側をサーバーに接続するために socket.io を使用しています。サーバーの起動時にサーバーをデータベースに接続すると思いますが、pg "docs"には多くの警告があります:「done()を使用しないと、悪いことが起こります」。
いつ使用すればよいですか?データベースへの接続を開き、その中にsocket.ioサーバーを作成しdone()
、各クエリの後に使用すると、30秒のアイドル後にエラーが発生し
Error: This socket has been ended by the other party
ます。socket.ioを作成してから接続を開く必要があるかもしれません各ユーザーセッション内のデータベース? または、現在開いていない場合、各クエリでデータベースへの接続を開きますか? 正直なところ、なぜこれを行う必要があるのか 、サーバーの起動時にデータベースへの単一の接続を作成して、この開閉の繰り返しの代わりにそれを介してすべてのクエリを送信できないのはなぜですか。
node.js - Postgres から文字列として返される enum 型の配列
カスタム列挙型が与えられた場合:
CREATE TYPE vehicle AS ENUM ('car', 'truck', 'bicycle');
そして、次のようなテーブル:
これがノード アプリケーションからクエリされると、次のようになります。
SELECT * FROM vehicle_events;
これは次のような json 構造を返します。
[{"timestamp": "January, 06 2016 23:04:56", "labels": "{'car'}", "mentions": [1,2,3,4]}]
私の質問は本当に、ラベル配列が文字列として返されるのはなぜですか (基本型の言及配列はそうではないことに注意してください)? これはの配列だからENUM
ですか?もしそうなら、どうすればそれを通常の配列に強制できますか? そして、なぜpostgresはこのようにそれを返すのですか?
sqlfiddle リンク: http://sqlfiddle.com/#!15/637ce/1
javascript - Node-postgres データベースに新しいレコードを挿入しても、新しいエントリのデータが返されない
クエリが実行されているルートは次のとおりです。
問題は、2 番目のコンソール内から参照しようとしている「結果」の値が基本的に空白であることです。
データベースで作成したばかりの行を表すオブジェクトを含む配列を result.rows に含めるべきではありませんか?