Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

Commit

Permalink
Close #70, timestamp columns for postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongho Nam committed Aug 25, 2022
1 parent 74056bd commit 326935d
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 5 deletions.
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ node_modules/
src/
lib/test/

*.js.map
*.*ignore
package-lock.json
tsconfig.api.json
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "safe-typeorm",
"version": "1.0.13",
"description": "Safe Relationship Decorators for the TypeORM",
"version": "1.0.14",
"description": "Make TypeORM much safer",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"scripts": {
Expand Down
24 changes: 24 additions & 0 deletions src/decorators/CreateTimestampColumn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ColumnOptions, CreateDateColumn } from "typeorm";

/**
* Creation timstamp column for `postgres`.
*
* When defining datetime column, time zone is very important when considering global
* service. However, default `CreateDateColumn` of `typeorm` does not archive the time zone
* when using `postgres` database. Furthermore, `typeorm` does not archive milliseconds.
*
* I think it's a critical mistake of `typeorm`, but they think it's not a bug but spec.
*
* Therefore, `safe-typeorm` supports custom creation timestamp column which supports time
* zone and milliseconds. When using `postgres` database, use this `CreateTimestampColumn`
* instead of the `CreateDateColumn`.
*
* @param options Additional options if required
* @returns Property decorator function
*/
export const CreateTimestampColumn = (options?: ColumnOptions) =>
CreateDateColumn({
...(options || {}),
precision: 3,
type: "timestamp with time zone",
});
24 changes: 24 additions & 0 deletions src/decorators/DeleteTimestampColumn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ColumnOptions, DeleteDateColumn } from "typeorm";

/**
* Deletion timstamp column for `postgres`.
*
* When defining datetime column, time zone is very important when considering global
* service. However, default `DeleteDateColumn` of `typeorm` does not archive the time zone
* when using `postgres` database. Furthermore, `typeorm` does not archive milliseconds.
*
* I think it's a critical mistake of `typeorm`, but they think it's not a bug but spec.
*
* Therefore, `safe-typeorm` supports custom deletion timestamp column which supports time
* zone and milliseconds. When using `postgres` database, use this `DeleteTimestampColumn`
* instead of the `DeleteDateColumn`.
*
* @param options Additional options if required
* @returns Property decorator function
*/
export const DeleteTimestampColumn = (options?: ColumnOptions) =>
DeleteDateColumn({
...(options || {}),
precision: 3,
type: "timestamp with time zone",
});
11 changes: 11 additions & 0 deletions src/decorators/TimestampColumn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Column } from "typeorm";
import { ColumnCommonOptions } from "typeorm/decorator/options/ColumnCommonOptions";
import { ColumnNumericOptions } from "typeorm/decorator/options/ColumnNumericOptions";

export const TimestampColumn = (
options?: ColumnCommonOptions & Omit<ColumnNumericOptions, "precision">,
) =>
Column("timestamp with time zone", {
...(options || {}),
precision: 3,
});
24 changes: 24 additions & 0 deletions src/decorators/UpdateTimestampColumn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ColumnOptions, UpdateDateColumn } from "typeorm";

/**
* Update timstamp column for `postgres`.
*
* When defining datetime column, time zone is very important when considering global
* service. However, default `UpdateDateColumn` of `typeorm` does not archive the time zone
* when using `postgres` database. Furthermore, `typeorm` does not archive milliseconds.
*
* I think it's a critical mistake of `typeorm`, but they think it's not a bug but spec.
*
* Therefore, `safe-typeorm` supports custom update timestamp column which supports time
* zone and milliseconds. When using `postgres` database, use this `UpdateTimestampColumn`
* instead of the `UpdateDateColumn`.
*
* @param options Additional options if required
* @returns Property decorator function
*/
export const UpdateTimestampColumn = (options?: ColumnOptions) =>
UpdateDateColumn({
...(options || {}),
precision: 3,
type: "timestamp with time zone",
});
7 changes: 6 additions & 1 deletion src/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export * from "./Belongs";
export * from "./EncryptedColumn";
export * from "./Has";
export * from "./Has";

export * from "./CreateTimestampColumn";
export * from "./DeleteTimestampColumn";
export * from "./TimestampColumn";
export * from "./UpdateTimestampColumn";
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib", /* Redirect output structure to the directory. */
Expand Down

0 comments on commit 326935d

Please sign in to comment.