Home > Blockchain >  Can't get data from postgresql database using knex
Can't get data from postgresql database using knex

Time:01-31

I'm struggling with dealing with a knex connections. I want to get some data from my pg db but all it does it's returning my select, not the actual data that I expect to get. This is what I do in index.js And this is my knex connection

I've tried googling it, but I can't find the proper instructions on it. Please, tell me what to do

CodePudding user response:

This is my working example with postgres without any framework

import knex from 'knex'
import configuration from './knexfile.js'

const connection = knex(configuration.development)

const res = await connection.from('tablename').select('id', 'content')

for (const row of res) {
  console.log(`id: ${row.id}, content: ${row.content}`)
}

Inside of file knexfile.js you need the config created by command npx knex init

  • Related