简体   繁体   中英

How to create a table with postgresql in nodejs without an ORM?

please I am trying to create a table with PostgreSQL using nodejs but I don't know how to go about it. I want the table to be created from the query without the use of an ORM

Install 'pg' package .

const pg = require('pg');
const db = new pg.Pool({
 host: 'SERVER_IP',
 database: 'DB_NAME',
 user: 'USER',
 password: 'DB_PASS',
 port: '5432'
});
db.query(“CREATE TABLE TABLE_NAME(id SERIAL PRIMARY KEY, xzy VARCHAR(40) NOT NULL,
abc VARCHAR(40) NOT NULL)”, (err, res) => {
console.log(err, res);
db.end();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM