2017-04-25 1 views
1

타임 스탬프 내 경로 응답으로 전송되고 있지만, 데이터베이스 내 테이블은 타임 스탬프

exports.up = (knex, Promise) => knex.schema.createTable('cohorts', (table) => { 
 
    table.increments('id') 
 
    .primary(); 
 
    table.string('name', 'varchar(6)') 
 
    .notNullable(); 
 
    table.string('type', 'varchar(3)') 
 
    .notNullable(); 
 
    table.date('q1_start_date') 
 
    .notNullable(); 
 
    table.date('q2_start_date') 
 
    .notNullable(); 
 
    table.date('q3_start_date') 
 
    .notNullable(); 
 
    table.date('q4_start_date') 
 
    .notNullable(); 
 
    table.date('graduation_date') 
 
    .notNullable(); 
 
    table.integer('campus_id') 
 
    .notNullable() 
 
    .references('id') 
 
    .inTable('campuses') 
 
    .onDelete('CASCADE'); 
 
    table.timestamps(true, true); 
 
}); 
 

 
exports.down = (knex, Promise) => knex.schema.dropTable('cohorts');

내가 확인할 때 내 마이그레이션에서 날짜를 사용하는 내 데이터베이스를 만들기 위해 PostgreSQL을 사용하고 표시되지 않습니다 데이터베이스의 내 테이블은 날짜 형식으로 저장됩니다. 그러나 bookshelf.js에 내 경로를 쓸 때 그 날짜는 타임 스탬프와 함께옵니다.

Here is my response with the timestamp

+0

제가 table.date'말인지는 ('아마 바로 날짜 열을 생성합니다 .. 출력에'.format ('YYYY-MM-DD')를 '사용하려고 노력하지만, 당신은 zeores를 s에 추가합니다. 선택된 –

답변

1

node-postgres 드라이버가 자동으로 실제 날짜와 시간이 자바 스크립트 날짜 객체로 변환, 데이터베이스에서 컬럼의 날짜 형식을 읽을 때.

당신이 좋아하는 경우에 당신은 문자열 형식으로 날짜를 반환하는 페이지 드라이버를 구성 할 수 있습니다

에이 패키지 https://github.com/brianc/node-pg-types

날짜 형식의 유형 ID : 유형에 대한 분석 설정

mikaelle=# select typname, oid, typarray from pg_type where 
pg_type.typname = 'date' order by oid; 
typname | oid | typarray 
---------+------+---------- 
date | 1082 |  1182 
(1 row) 

그리고 코드 수 이런 식으로 할 것은?

var types = require('pg').types 
types.setTypeParser(1082, function(val) { 
    return val; // just pass the string 
})