當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript pg.connect函數代碼示例

本文整理匯總了TypeScript中pg.connect函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript connect函數的具體用法?TypeScript connect怎麽用?TypeScript connect使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了connect函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: d

  return new Promise<T | null>((resolve: (val: T | null) => void, reject: (reason: any) => void) => {

    pg.connect(connection, (connectErr: Error, client: pg.Client, done: ((doneErr?: any) => void)) => {

      d("sqlOne running connect callback for", connection, query);

      if (connectErr) {
        return reject(connectErr);
      }

      client.query(query, (queryErr: Error, result: pg.QueryResult) => {
        done(); // release client back to pool
        if  (queryErr) {
          reject(queryErr);
        } else if (result && result.rows) {
          if (result.rows.length >= 1) {
            resolve(result.rows[0] as T);
          } else {
            resolve(null);
          }
        } else {
          reject(Error("Bad result in sqlOne"));
        }
      });

    });

  })
開發者ID:jw120,項目名稱:fcc-url-shortener,代碼行數:28,代碼來源:pg-prom.ts

示例2: function

exports.index = function (req, res) {
    pg.connect(c.conf, function (err, client, done) {
        if (err) {
            res.render('err', {
                msg: 'データベースとの接続でエラーが出ました。'
            })
			console.log(err);
        } else {
            if (req.session.login == true) {
                client.query("SELECT id, name_jp, bt_order FROM diag_category ORDER BY id", function (err, result) {
                    done();
                    //console.log(result);
                    //console.log(f.makeOrganList(result));
                    res.render('search', {
                        title: '所見閲覧システム',
                        organ: f.makeOrganList(result)
                    });
                });
            } else {
                res.render('err', {
                    msg: 'ログインしていません。'
                });
            }
        }
    });
};
開發者ID:KoichiHirahata,項目名稱:FindingsSite,代碼行數:26,代碼來源:search.ts

示例3: function

exports.index = function (req, res) {
    pg.connect(c.conf, function (err, client, done) {
        if (err) {
            res.render('err', {
                msg: 'データベースとの接続でエラーが出ました。'
            })
			console.log(err);
        } else {
            if (req.session.login != true) {
                res.render('err', {
                    msg: 'ログインしていません。'
                });
            } else if (req.body.func === "get_diag_name") {
                client.query("SELECT start_no, end_no FROM diag_category WHERE id=\'" + escapeStr(req.body.organ) + "\'", function (err, result) {
                    //res.send(result);
                    done();
                    //console.log("[result.rows[0].start_no]:" + result.rows[0].start_no + "[result.rows[0].end_no]:" + result.rows[0].end_no);
                    client.query("SELECT no, name_jp FROM diag_name WHERE no >= " + result.rows[0].start_no
                        + " AND no <= " + result.rows[0].end_no + " ORDER BY diag_order, no", function (err, result) {
                            done();
                            //console.log(result);
                            res.send(result);
                        });
                });
            } else if (req.body.func === "search") {
                var SQL: string = "SELECT exam_id, to_char(exam_day,\'yyyy/mm/dd\') AS e_day, exam.pt_id AS p_id, pt_name, exam_type.name_jp AS type_name "
                    + "FROM exam, patient, exam_type ";
                var criteria: string = "WHERE exam.pt_id=patient.pt_id AND exam.exam_type=exam_type.type_no ";

                console.log(req.body.diag_code);
                if (escapeStr(req.body.diag_code)) {
                    SQL += ", diag ";
                    criteria += " AND exam.exam_id=diag.exam_no AND diag_code=" + escapeStr(req.body.diag_code);
                }

                if (req.body.date_from.length != 0) {
                    criteria += "AND exam_day >= " + escapeStr(req.body.date_from);
                }

                if (req.body.date_to.length != 0) {
                    criteria += "AND exam_day >= " + escapeStr(req.body.date_to);
                }

                if (req.body.patho.length != 0) {
                    criteria += "AND patho_result LIKE '%" + escapeStr(req.body.patho) + "%'";
                }

                SQL += criteria + " ORDER BY exam_day DESC";

                console.log(SQL);

                client.query(SQL, function (err, result) {
                    //console.log(result);
                    res.send(result);
                    done();
                });
            }
        }
    });
};
開發者ID:KoichiHirahata,項目名稱:FindingsSite,代碼行數:60,代碼來源:search_post.ts

示例4: function

exports.index = function (req, res) {
    pg.connect(c.conf, function (err, client, done) {
        if (err) {
            res.render('err', {
                msg: 'データベースとの接続でエラーが出ました。'
            })
			console.log(err);
        } else {
            if (req.session.login === true && req.body.func != "login") {
                client.query("SELECT pt_name, exam_id, to_char(birthday, \'yyyy/mm/dd\') AS b_day, to_char(exam_day,\'yyyy/mm/dd\') AS e_day, name_jp "
                    + "FROM patient, exam, exam_type "
                    + "WHERE exam.pt_id=\'" + escapeStr(req.body.pt_id) + '\' '
                    + "AND patient.pt_id=exam.pt_id AND exam.exam_type=exam_type.type_no ORDER BY exam_day DESC", function (err, result) {
                        res.send(result);
                        done();
                    });
            } else {
                client.query("SELECT op_name, pw FROM operator WHERE operator_id=\'" + escapeStr(req.body.operator_id) + '\'', function (err, result) {
                    if ((result.rows.length === 0) || (escapeStr(req.body.pw) != result.rows[0].pw)) {
                        req.session.login = false;
                        res.render('err', {
                            msg: 'IDまたはパスワードが間違っています。'
                        })
					} else {
                        req.session.login = true;
                        req.session.name = req.body.operator_id;
                        res.redirect('/');
                    }
                    done();
                });
            }
        }
    });
};
開發者ID:KoichiHirahata,項目名稱:FindingsSite,代碼行數:34,代碼來源:login_post.ts

示例5: function

function withDb<T>(fn: (db: pg.Client) => T) {
    pg.connect(config.database.connectionString, function(err, client, done) {
        if (err) {
            log.error('Failed to connect to the database with ' + config.database.connectionString + ": ", err);
            throw err;
        }
        try {
            return fn(client);
        }
        finally {
            done();
        }
    });
}
開發者ID:PhilipDavis,項目名稱:react-redux,代碼行數:14,代碼來源:withDb.ts

示例6: Promise

        var promise = new Promise(function (resolve, reject) {
            pg.connect(connectionString, function(err, client, done) {
                if (err) reject(err);
                else client.query(query, parameters, function(err, result) {
                    if (err) {
                        reject(err);
                        console.log(err);
                    }
                    else resolve(result);

                    done();
                });
            });	
        });
開發者ID:SleepyPierre,項目名稱:BarHigher_Proto,代碼行數:14,代碼來源:database.ts

示例7: function

exports.index = function(req, res) {
    pg.connect(c.conf, function(err, client, done) {
        if (err) {
            res.render('err', {
                msg: 'データベースとの接続でエラーが出ました。'
            })
            console.log(err);
        } else {
            if (req.session.login === true) {
                client.query("SELECT patient.pt_id AS pt_id, pt_name, exam_id, to_char(birthday, \'yyyy/mm/dd\') AS b_day, to_char(exam_day,\'yyyy/mm/dd\') AS e_day, name_jp "
                    + "FROM patient, exam, exam_type "
                    + "WHERE exam.pt_id=\'" + escapeStr(req.body.pt_id) + '\' '
                    + "AND patient.pt_id=exam.pt_id AND exam.exam_type=exam_type.type_no ORDER BY exam_day DESC", function(err, result) {
                        res.send(result);
                        done();
                    });
            }
        }
    });
};
開發者ID:KoichiHirahata,項目名稱:FindingsSite,代碼行數:20,代碼來源:index_post.ts

示例8: index

export function index(req: any, res: any) {
    var pt_id = req.query.pt_id;

    pg.connect(c.conf, function(err, client, done) {
        if (err) {
            res.render('err', {
                msg: 'データベースとの接続でエラーが出ました。'
            })
            console.log(err);
        } else {
            client.query("SELECT op_name FROM operator WHERE operator_id=\'" + escapeStr(req.session.name) + '\'', function(err, result) {
                done();
                res.render('index', {
                    title: c.title,
                    usr: 'ユーザー:' + result.rows[0].op_name,
                    msg: '患者IDを入力してください。',
                    patient_id: pt_id
                });
            });
        }
    });
}
開發者ID:KoichiHirahata,項目名稱:FindingsSite,代碼行數:22,代碼來源:index.ts

示例9: initDb

export function initDb() {
    dbConnect(databaseUrl, (err, client, done) => {
        client.query("select 1 from information_schema.tables where table_name='actor'", (err, result) =>{
            if(result.rows.length == 0){
                client.query(
                    `create table actor(id serial, first_name varchar, last_name varchar, username varchar); \
                    insert into actor(first_name, last_name, username) values('1', '2', '3');
                    `, (err, result) =>{});
            }
        });
    });
}
開發者ID:ip821,項目名稱:angular2-sample,代碼行數:12,代碼來源:initDb.ts


注:本文中的pg.connect函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。