teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

6

文章の修正

2018/04/04 07:02

投稿

ryo_274
ryo_274

スコア7

title CHANGED
File without changes
body CHANGED
@@ -40,4 +40,4 @@
40
40
 
41
41
  ### 補足情報
42
42
  Node.js 6.10
43
- node-postgres 7.0 https://node-postgres.com/
43
+ [node-postgres 7.0](https://node-postgres.com/)

5

文章の修正

2018/04/04 07:02

投稿

ryo_274
ryo_274

スコア7

title CHANGED
File without changes
body CHANGED
@@ -40,4 +40,4 @@
40
40
 
41
41
  ### 補足情報
42
42
  Node.js 6.10
43
- node-postgres 7.0
43
+ node-postgres 7.0 https://node-postgres.com/

4

文章の修正

2018/04/04 07:01

投稿

ryo_274
ryo_274

スコア7

title CHANGED
File without changes
body CHANGED
@@ -28,6 +28,16 @@
28
28
  id: 123
29
29
  }
30
30
  ```
31
+ ### 試したこと
32
+ thisを使用する
33
+ ```Node.js
34
+ let id = 0;
35
+ client.query("SQL文", (err, res) => {
36
+ if (err) throw err;
37
+ this.id = res.rows[0].id;
38
+ });
39
+ ```
40
+
31
41
  ### 補足情報
32
42
  Node.js 6.10
33
43
  node-postgres 7.0

3

文章の修正

2018/04/04 07:00

投稿

ryo_274
ryo_274

スコア7

title CHANGED
File without changes
body CHANGED
@@ -28,15 +28,6 @@
28
28
  id: 123
29
29
  }
30
30
  ```
31
- ### 試したこと
32
- thisを使う
33
- ```Node.js
34
- let id = 0;
35
- client.query(sql, (err, res) => {
36
- if (err) throw err;
37
- this.id = res.rows[0].id;
38
- });
39
- ```
40
31
  ### 補足情報
41
32
  Node.js 6.10
42
33
  node-postgres 7.0

2

文章の修正

2018/04/04 06:53

投稿

ryo_274
ryo_274

スコア7

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,7 @@
1
1
  ### 前提・実現したいこと
2
2
  Node.jsでnode-postgresを使用してDB接続を行っているのですが、
3
3
  client.query()のcallback関数の値をclient.query()の外のidに代入したいです。
4
+ callback関数を使用しない方法などでも構いません。
4
5
 
5
6
  JavaやPythonの経験は多少ありますが、Node.jsの経験はあまりありません。
6
7
  そのため、callback関数などの使い方もあまりわかっていません。

1

文章の修正

2018/04/04 05:33

投稿

ryo_274
ryo_274

スコア7

title CHANGED
@@ -1,1 +1,1 @@
1
- client.query()戻り値を渡したい
1
+ Node.jsでPostgreSQL結果callback関数の外の変数に渡したい
body CHANGED
@@ -1,6 +1,6 @@
1
1
  ### 前提・実現したいこと
2
2
  Node.jsでnode-postgresを使用してDB接続を行っているのですが、
3
- client.query()の戻り値をclient.query()の外のidに代入したいです。
3
+ client.query()のcallback関数の値をclient.query()の外のidに代入したいです。
4
4
 
5
5
  JavaやPythonの経験は多少ありますが、Node.jsの経験はあまりありません。
6
6
  そのため、callback関数などの使い方もあまりわかっていません。