This repository has been archived by the owner on Mar 4, 2019. It is now read-only.
This repository has been archived by the owner on Mar 4, 2019. It is now read-only.
Problem successfully persisting or querying data, despite db.listTables() functioning correctly #663
Closed
Description
Summary
Massive appears to successfully be connecting to the database, as witnessed by req.app.get('db').listTables()
printing out the correct list of database tables. However, any attempts to persist or query data always return null.
Example
const express = require('express')
const massive = require('massive')
const { Client } = require('pg')
const connection = {
host: process.env.DATA_POSTGRES_HOST,
port: 5432,
database: 'appdb',
user: process.env.DATA_POSTGRES_USER,
password: process.env.DATA_POSTGRES_PASS,
max: 10,
min: 0
}
const client = new Client(connection)
client.connect()
client.query('CREATE TABLE IF NOT EXISTS account(email varchar(355) unique not null primary key, password varchar(50) not null')
.catch(e => console.error(e.stack))
.then(() => client.end())
const db = massive(connection)
.then(db => {
app.set('db', db)
console.log(app.get('db').listTables()) // PRINTS [ 'account' ] AS EXPECTED
app.post('/signup', (req, res) => {
req.app.get('db').account.save({ email: req.body.email, password: req.body.password }).then(data => {
console.log(data) // PRINTS NULL
})
})
app.post('/getaccountinfo', (req, res) => {
req.app.get('db').account.findOne({ email: req.body.email }).then(data => {
console.log(data) // PRINTS NULL
})
})
app.listen(
port,
'0.0.0.0',
() => console.log(`Example app listening on port ${port}!`)
)
})
Metadata
Assignees
Labels
No labels
Activity