Skip to content

Commit

Permalink
feat(datetime): use timestamptz for datetimes (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldcaddy77 authored May 30, 2021
1 parent d54fc78 commit b950c7f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/decorators/CreatedAtField.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { GraphQLISODateTime } from 'type-graphql';
import { CreateDateColumn } from 'typeorm';

import { DecoratorCommonOptions } from '../metadata';
import { DateTimeWhereOperator } from '../torm';
import { composeMethodDecorators } from '../utils';
Expand All @@ -13,7 +12,7 @@ interface CreatedAtFieldOptions extends DecoratorCommonOptions {
export function CreatedAtField(options: CreatedAtFieldOptions = {}): any {
const factories = getCombinedDecorator({
fieldType: 'datetime',
dbType: 'timestamp',
dbType: 'timestamptz',
gqlFieldType: GraphQLISODateTime,
warthogColumnMeta: { specialType: 'created-at', readonly: true, ...options },
dbDecorator: CreateDateColumn
Expand Down
4 changes: 1 addition & 3 deletions src/decorators/DateField.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { GraphQLISODateTime } from 'type-graphql';

import { DecoratorCommonOptions } from '../metadata';
import { ColumnType, DateWhereOperator } from '../torm';
import { composeMethodDecorators } from '../utils';

import { getCombinedDecorator } from './getCombinedDecorator';

interface DateFieldOptions extends DecoratorCommonOptions {
Expand All @@ -21,7 +19,7 @@ export function DateField(options: DateFieldOptions = {}): any {
fieldType: 'date',
warthogColumnMeta: options,
gqlFieldType: GraphQLISODateTime,
dbType: options.dataType || 'timestamp',
dbType: options.dataType || 'timestamptz',
dbColumnOptions: { ...nullableOption, ...defaultOption }
});

Expand Down
6 changes: 2 additions & 4 deletions src/decorators/DateTimeField.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// https://www.postgresql.org/docs/10/datatype-datetime.html
import { GraphQLISODateTime } from 'type-graphql';

import { DecoratorCommonOptions } from '../metadata';
import { DateTimeString } from '../core';
import { DecoratorCommonOptions } from '../metadata';
import { DateTimeWhereOperator } from '../torm';
import { composeMethodDecorators } from '../utils';

import { getCombinedDecorator } from './getCombinedDecorator';

interface DateTimeFieldOptions extends DecoratorCommonOptions {
Expand All @@ -22,7 +20,7 @@ export function DateTimeField(options: DateTimeFieldOptions = {}): any {
fieldType: 'datetime',
warthogColumnMeta: options,
gqlFieldType: GraphQLISODateTime,
dbType: 'timestamp',
dbType: 'timestamptz',
dbColumnOptions: { ...nullableOption, ...defaultOption }
});

Expand Down
3 changes: 1 addition & 2 deletions src/decorators/UpdatedAtField.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { GraphQLISODateTime } from 'type-graphql';
import { UpdateDateColumn } from 'typeorm';

import { DecoratorCommonOptions } from '../metadata';
import { DateTimeWhereOperator } from '../torm';
import { composeMethodDecorators } from '../utils';
Expand All @@ -13,7 +12,7 @@ interface UpdatedAtFieldOptions extends DecoratorCommonOptions {
export function UpdatedAtField(options: UpdatedAtFieldOptions = {}): any {
const factories = getCombinedDecorator({
fieldType: 'datetime',
dbType: 'timestamp',
dbType: 'timestamptz',
gqlFieldType: GraphQLISODateTime,
warthogColumnMeta: { specialType: 'updated-at', nullable: true, readonly: true, ...options },
dbDecorator: UpdateDateColumn
Expand Down

0 comments on commit b950c7f

Please sign in to comment.