'use strict';

var _ = require('lodash');
var config = require('../../config/environment')

// Get list of tablespaces
exports.index = function(req, res) {

  config.knex.raw("SELECT * FROM pg_tablespace").then(function (data) {
    res.json(_.map(data.rows, function(item) { return item }));
  })

};

exports.size = function(req, res) {

  var tbsp = req.param('name');

  config.knex.raw("SELECT pg_tablespace_size(?)", [tbsp]).then(function (data) {
    res.json(data.rows[0].pg_tablespace_size);
  })
  .catch(function (err) {
    console.error(err);
    res.json(err);
  })

};
