当前位置: 首页>>代码示例>>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;未经允许,请勿转载。