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

Commit 326935d

Browse files
author
Jeongho Nam
committed
Close #70, timestamp columns for postgres
1 parent 74056bd commit 326935d

8 files changed

+92
-5
lines changed

.npmignore

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ node_modules/
55
src/
66
lib/test/
77

8-
*.js.map
98
*.*ignore
109
package-lock.json
1110
tsconfig.api.json

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "safe-typeorm",
3-
"version": "1.0.13",
4-
"description": "Safe Relationship Decorators for the TypeORM",
3+
"version": "1.0.14",
4+
"description": "Make TypeORM much safer",
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",
77
"scripts": {
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { ColumnOptions, CreateDateColumn } from "typeorm";
2+
3+
/**
4+
* Creation timstamp column for `postgres`.
5+
*
6+
* When defining datetime column, time zone is very important when considering global
7+
* service. However, default `CreateDateColumn` of `typeorm` does not archive the time zone
8+
* when using `postgres` database. Furthermore, `typeorm` does not archive milliseconds.
9+
*
10+
* I think it's a critical mistake of `typeorm`, but they think it's not a bug but spec.
11+
*
12+
* Therefore, `safe-typeorm` supports custom creation timestamp column which supports time
13+
* zone and milliseconds. When using `postgres` database, use this `CreateTimestampColumn`
14+
* instead of the `CreateDateColumn`.
15+
*
16+
* @param options Additional options if required
17+
* @returns Property decorator function
18+
*/
19+
export const CreateTimestampColumn = (options?: ColumnOptions) =>
20+
CreateDateColumn({
21+
...(options || {}),
22+
precision: 3,
23+
type: "timestamp with time zone",
24+
});
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { ColumnOptions, DeleteDateColumn } from "typeorm";
2+
3+
/**
4+
* Deletion timstamp column for `postgres`.
5+
*
6+
* When defining datetime column, time zone is very important when considering global
7+
* service. However, default `DeleteDateColumn` of `typeorm` does not archive the time zone
8+
* when using `postgres` database. Furthermore, `typeorm` does not archive milliseconds.
9+
*
10+
* I think it's a critical mistake of `typeorm`, but they think it's not a bug but spec.
11+
*
12+
* Therefore, `safe-typeorm` supports custom deletion timestamp column which supports time
13+
* zone and milliseconds. When using `postgres` database, use this `DeleteTimestampColumn`
14+
* instead of the `DeleteDateColumn`.
15+
*
16+
* @param options Additional options if required
17+
* @returns Property decorator function
18+
*/
19+
export const DeleteTimestampColumn = (options?: ColumnOptions) =>
20+
DeleteDateColumn({
21+
...(options || {}),
22+
precision: 3,
23+
type: "timestamp with time zone",
24+
});

src/decorators/TimestampColumn.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Column } from "typeorm";
2+
import { ColumnCommonOptions } from "typeorm/decorator/options/ColumnCommonOptions";
3+
import { ColumnNumericOptions } from "typeorm/decorator/options/ColumnNumericOptions";
4+
5+
export const TimestampColumn = (
6+
options?: ColumnCommonOptions & Omit<ColumnNumericOptions, "precision">,
7+
) =>
8+
Column("timestamp with time zone", {
9+
...(options || {}),
10+
precision: 3,
11+
});
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { ColumnOptions, UpdateDateColumn } from "typeorm";
2+
3+
/**
4+
* Update timstamp column for `postgres`.
5+
*
6+
* When defining datetime column, time zone is very important when considering global
7+
* service. However, default `UpdateDateColumn` of `typeorm` does not archive the time zone
8+
* when using `postgres` database. Furthermore, `typeorm` does not archive milliseconds.
9+
*
10+
* I think it's a critical mistake of `typeorm`, but they think it's not a bug but spec.
11+
*
12+
* Therefore, `safe-typeorm` supports custom update timestamp column which supports time
13+
* zone and milliseconds. When using `postgres` database, use this `UpdateTimestampColumn`
14+
* instead of the `UpdateDateColumn`.
15+
*
16+
* @param options Additional options if required
17+
* @returns Property decorator function
18+
*/
19+
export const UpdateTimestampColumn = (options?: ColumnOptions) =>
20+
UpdateDateColumn({
21+
...(options || {}),
22+
precision: 3,
23+
type: "timestamp with time zone",
24+
});

src/decorators/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
export * from "./Belongs";
22
export * from "./EncryptedColumn";
3-
export * from "./Has";
3+
export * from "./Has";
4+
5+
export * from "./CreateTimestampColumn";
6+
export * from "./DeleteTimestampColumn";
7+
export * from "./TimestampColumn";
8+
export * from "./UpdateTimestampColumn";

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// "checkJs": true, /* Report errors in .js files. */
1212
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
1313
"declaration": true, /* Generates corresponding '.d.ts' file. */
14-
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
14+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
1515
"sourceMap": true, /* Generates corresponding '.map' file. */
1616
// "outFile": "./", /* Concatenate and emit output to single file. */
1717
"outDir": "./lib", /* Redirect output structure to the directory. */

0 commit comments

Comments
 (0)