12345678910111213141516171819202122232425262728 |
- const pgp = require('pg-promise')();
- const fs = require('fs');
- // 连接到数据库
- const db = pgp({
- user: 'postgres',
- password: 'postgres',
- host: 'localhost',
- port: 25432,
- database: 'postgres'
- });
- let initDataSQL = fs.readFileSync("../data/init-data.sql").toString()
- // 执行SELECT语句并返回结果的函数
- async function main() {
- try {
- // 查询:数据库版本信息
- const data = await db.any(initDataSQL);
- console.log(data)
- return data;
- } catch (error) {
- console.error('Error executing query:', error);
- return null;
- }
- }
- // 调用函数并处理结果
- main()
|