2016-05-05 3 views
4

Ich erstelle eine Tabelle mit Knex.JS, und die Tabelle hat eine Spalte für einen Währungswert.Wie lautet der numerische Typ in KnexJS (Postgres)?

Zum Beispiel, hier ist die Spalte amount:

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

Derzeit bin ich mit dem float Typ, aber ich mag den numeric Typen verwenden. Was entspricht dem Typ numeric in Knex.JS?

Danke.

Antwort

4

Für Währung decimal ist am besten entsprechen, so kann der Code wie folgt aussehen:

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

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

sehen
Verwandte Themen