-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
157 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
typeorm/typeorm-store/src/decorators/columns/BigDecimalColumn.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {bigdecimalTransformer} from '../../transformers' | ||
import {Column} from './Column' | ||
import {ColumnCommonOptions} from './common' | ||
|
||
export type BigDecimalColumnOptions = Pick<ColumnCommonOptions, 'name' | 'unique' | 'nullable' | 'default' | 'comment'> | ||
|
||
export function BigDecimalColumn(options?: BigDecimalColumnOptions): PropertyDecorator { | ||
return Column('numeric', {...options, transformer: bigdecimalTransformer}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {bigintTransformer} from '../../transformers' | ||
import {Column} from './Column' | ||
import {ColumnCommonOptions} from './common' | ||
|
||
export type BigIntColumnOptions = Pick<ColumnCommonOptions, 'name' | 'unique' | 'nullable' | 'default' | 'comment'> | ||
|
||
export function BigIntColumn(options?: BigIntColumnOptions): PropertyDecorator { | ||
return Column('numeric', {...options, transformer: bigintTransformer}) | ||
} |
11 changes: 11 additions & 0 deletions
11
typeorm/typeorm-store/src/decorators/columns/BooleanColumn.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {Column} from './Column' | ||
import {ColumnCommonOptions} from './common' | ||
|
||
export type BooleanColumnOptions = Pick< | ||
ColumnCommonOptions, | ||
'name' | 'unique' | 'nullable' | 'default' | 'comment' | 'array' | ||
> | ||
|
||
export function BooleanColumn(options?: BooleanColumnOptions): PropertyDecorator { | ||
return Column('bool', options) | ||
} |
11 changes: 11 additions & 0 deletions
11
typeorm/typeorm-store/src/decorators/columns/BytesColumn.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {Column} from './Column' | ||
import {ColumnCommonOptions} from './common' | ||
|
||
export type BytesColumnOptions = Pick< | ||
ColumnCommonOptions, | ||
'name' | 'unique' | 'nullable' | 'default' | 'comment' | 'array' | ||
> | ||
|
||
export function BytesColumn(options?: BytesColumnOptions): PropertyDecorator { | ||
return Column('bytea', options) | ||
} |
11 changes: 11 additions & 0 deletions
11
typeorm/typeorm-store/src/decorators/columns/DateTimeColumn.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {Column} from './Column' | ||
import {ColumnCommonOptions} from './common' | ||
|
||
export type DateTimeColumnOptions = Pick< | ||
ColumnCommonOptions, | ||
'name' | 'unique' | 'nullable' | 'default' | 'comment' | 'array' | ||
> | ||
|
||
export function DateTimeColumn(options?: DateTimeColumnOptions): PropertyDecorator { | ||
return Column('timestamp with time zone', options) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {floatTransformer} from '../../transformers' | ||
import {Column} from './Column' | ||
import {ColumnCommonOptions} from './common' | ||
|
||
export type FloatColumnOptions = Pick<ColumnCommonOptions, 'name' | 'unique' | 'nullable' | 'default' | 'comment'> | ||
|
||
export function FloatColumn(options?: FloatColumnOptions): PropertyDecorator { | ||
return Column('numeric', {...options, transformer: floatTransformer}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {Column} from './Column' | ||
import {ColumnCommonOptions, ColumnOptions} from './common' | ||
|
||
export type IntColumnOptions = Pick< | ||
ColumnCommonOptions, | ||
'name' | 'unique' | 'nullable' | 'default' | 'comment' | 'array' | ||
> | ||
|
||
export function IntColumn(options?: IntColumnOptions): PropertyDecorator { | ||
return Column('int4', options) | ||
} |
11 changes: 11 additions & 0 deletions
11
typeorm/typeorm-store/src/decorators/columns/StringColumn.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {Column} from './Column' | ||
import {ColumnCommonOptions} from './common' | ||
|
||
export type StringColumnOptions = Pick< | ||
ColumnCommonOptions, | ||
'name' | 'unique' | 'nullable' | 'default' | 'comment' | 'array' | ||
> | ||
|
||
export function StringColumn(options?: StringColumnOptions): PropertyDecorator { | ||
return Column('text', options) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
export * from './common' | ||
export * from './Column' | ||
export * from './PrimaryColumn' | ||
export * from './BigDecimalColumn' | ||
export * from './BigIntColumn' | ||
export * from './BooleanColumn' | ||
export * from './BytesColumn' | ||
export * from './DateTimeColumn' | ||
export * from './FloatColumn' | ||
export * from './IntColumn' | ||
export * from './StringColumn' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './database' | ||
export {EntityClass, FindManyOptions, FindOneOptions, Store} from './store' | ||
export * from './decorators' | ||
export * from './transformers' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {ValueTransformer} from 'typeorm' | ||
|
||
export const bigintTransformer: ValueTransformer = { | ||
to(x?: bigint) { | ||
return x?.toString() | ||
}, | ||
from(s?: string): bigint | undefined { | ||
return s == null ? undefined : BigInt(s) | ||
}, | ||
} | ||
|
||
export const floatTransformer: ValueTransformer = { | ||
to(x?: number) { | ||
return x?.toString() | ||
}, | ||
from(s?: string): number | undefined { | ||
return s == null ? undefined : Number(s) | ||
}, | ||
} | ||
|
||
const decimal = { | ||
get BigDecimal(): any { | ||
throw new Error('Package `@subsquid/big-decimal` is not installed') | ||
}, | ||
} | ||
|
||
try { | ||
Object.defineProperty(decimal, 'BigDecimal', { | ||
value: require('@subsquid/big-decimal').BigDecimal, | ||
}) | ||
} catch (e) {} | ||
|
||
export const bigdecimalTransformer: ValueTransformer = { | ||
to(x?: any) { | ||
return x?.toString() | ||
}, | ||
from(s?: any): any | undefined { | ||
return s == null ? undefined : decimal.BigDecimal(s) | ||
}, | ||
} |