Skip to content
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
@johncmunson

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}!`)
    )
  })

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions