Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the numeric type equivalent in KnexJS (Postgres)?

I am creating a table using Knex.JS, and the table has a column for a currency value.

For example, here is the column amount:

knex.schema.createTable('payment', function(table) {
  table.increments();
  table.float('amount');
})

Currently, I am using the float type, but I'd like to use the numeric type. What is the equivalent of the numeric type in Knex.JS?

Thanks.

like image 229
aashah7 Avatar asked May 05 '16 19:05

aashah7


1 Answers

For currency decimal is best match, so your code may look like:

knex.schema.createTable('payment', function(table) {
  table.increments();
  table.decimal('amount',14,2); // e.g. 14 positions, 2 for the cents
});

see http://knexjs.org/#Schema-decimal

like image 101
flaviodesousa Avatar answered Oct 21 '22 21:10

flaviodesousa