-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
4bd6489
commit 2de6e8e
Showing
3 changed files
with
33 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { type ClickhouseSchema, type ChSchemaDefinition } from '@clickhouse-schema-core/clickhouse_schema' | ||
import { type ClickhouseSchema } from '@clickhouse-schema-core/clickhouse_schema' | ||
import { type ChDataType } from '@clickhouse-schema-data-types/index' | ||
import { type InferArray, type InferEnum, type InferJSON, type InferNullable, type InferTypeFromMap } from '@clickhouse-schema-utils/util' | ||
|
||
/** InferSchemaClickhouseSchemaType is a type that takes a ClickhouseSchema and returns the typescript that it represents */ | ||
export type InferClickhouseSchemaType<T extends ClickhouseSchema<ChSchemaDefinition>> = { [K in keyof T['schema']]: InferType<T['schema'][K]['type']> } | ||
export type InferClickhouseSchemaType<T extends ClickhouseSchema<any>> = { [K in keyof T['schema']]: InferType<T['schema'][K]['type']> } | ||
|
||
/** InferType is a type that takes a ChDataType and returns the typescript that it represents */ | ||
type InferType<T extends ChDataType> = T['dataTypeMarker'] extends 'Array' ? InferArray<T> : T['dataTypeMarker'] extends 'Enum' ? InferEnum<T> : T['dataTypeMarker'] extends 'JSON' ? InferJSON<T> : T['dataTypeMarker'] extends 'Nullable' ? InferNullable<T> : InferTypeFromMap<T['typeStr']> | ||
export type InferType<T extends ChDataType> = T['dataTypeMarker'] extends 'Array' ? InferArray<T> : T['dataTypeMarker'] extends 'Enum' ? InferEnum<T> : T['dataTypeMarker'] extends 'JSON' ? InferJSON<T> : T['dataTypeMarker'] extends 'Nullable' ? InferNullable<T> : InferTypeFromMap<T['typeStr']> |
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,4 +1,5 @@ | ||
import { ClickhouseSchema, type ChSchemaOptions } from '@clickhouse-schema-core/clickhouse_schema' | ||
import { type InferClickhouseSchemaType } from '@clickhouse-schema-core/infer_schema_type' | ||
import { ClickhouseTypes } from '@clickhouse-schema-data-types/index' | ||
|
||
describe('ClickhouseSchema Tests', () => { | ||
|
@@ -9,13 +10,14 @@ describe('ClickhouseSchema Tests', () => { | |
email: { type: ClickhouseTypes.CHString }, | ||
age: { type: ClickhouseTypes.CHUInt8 } | ||
} | ||
const options: ChSchemaOptions = { | ||
const options: ChSchemaOptions<typeof schemaDefinition> = { | ||
primary_key: 'id', | ||
table_name: 'users_table' | ||
} | ||
|
||
const schema = new ClickhouseSchema(schemaDefinition, options) | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
type ChSchemaDefinition = InferClickhouseSchemaType<typeof schema> | ||
expect(schema.GetOptions()).toEqual(options) | ||
}) | ||
|
||
|
@@ -26,7 +28,7 @@ describe('ClickhouseSchema Tests', () => { | |
email: { type: ClickhouseTypes.CHString }, | ||
age: { type: ClickhouseTypes.CHUInt8 } | ||
} | ||
const options: ChSchemaOptions = { | ||
const options: ChSchemaOptions<typeof schemaDefinition> = { | ||
table_name: 'users_table' | ||
} | ||
|
||
|
@@ -42,7 +44,7 @@ describe('ClickhouseSchema Tests', () => { | |
email: { type: ClickhouseTypes.CHString }, | ||
age: { type: ClickhouseTypes.CHUInt8 } | ||
} | ||
const options: ChSchemaOptions = { | ||
const options: ChSchemaOptions<typeof schemaDefinition> = { | ||
primary_key: 'id', | ||
table_name: 'users_table' | ||
} | ||
|
@@ -60,7 +62,7 @@ describe('ClickhouseSchema Tests', () => { | |
email: { type: ClickhouseTypes.CHString, default: '[email protected]' }, | ||
age: { type: ClickhouseTypes.CHUInt8 } | ||
} | ||
const options: ChSchemaOptions = { | ||
const options: ChSchemaOptions<typeof schemaDefinition> = { | ||
primary_key: 'id', | ||
table_name: 'users_table' | ||
} | ||
|
@@ -78,7 +80,7 @@ describe('ClickhouseSchema Tests', () => { | |
email: { type: ClickhouseTypes.CHString, default: '[email protected]' }, | ||
age: { type: ClickhouseTypes.CHUInt8, default: 18 } | ||
} | ||
const options: ChSchemaOptions = { | ||
const options: ChSchemaOptions<typeof schemaDefinition> = { | ||
primary_key: 'id', | ||
table_name: 'users_table', | ||
additional_options: ['COMMENT \'This table provides user details\''] | ||
|
@@ -95,7 +97,7 @@ describe('ClickhouseSchema Tests', () => { | |
name: { type: ClickhouseTypes.CHString, default: 'John Doe' }, | ||
email: { type: ClickhouseTypes.CHString } | ||
} | ||
const options: ChSchemaOptions = { | ||
const options: ChSchemaOptions<typeof schemaDefinition> = { | ||
table_name: 'users_table', | ||
order_by: 'id' | ||
} | ||
|
@@ -111,7 +113,7 @@ describe('ClickhouseSchema Tests', () => { | |
name: { type: ClickhouseTypes.CHString, default: 'John Doe' }, | ||
email: { type: ClickhouseTypes.CHString } | ||
} | ||
const options: ChSchemaOptions = { | ||
const options: ChSchemaOptions<typeof schemaDefinition> = { | ||
table_name: 'users_table', | ||
primary_key: 'id', | ||
on_cluster: 'users_cluster' | ||
|
@@ -123,19 +125,18 @@ describe('ClickhouseSchema Tests', () => { | |
}) | ||
|
||
it('should correctly generate a create table query with a specified engine', () => { | ||
const schemaDefinition = { | ||
const schema = new ClickhouseSchema({ | ||
id: { type: ClickhouseTypes.CHUUID }, | ||
name: { type: ClickhouseTypes.CHString, default: 'John Doe' }, | ||
email: { type: ClickhouseTypes.CHString } | ||
} | ||
const options: ChSchemaOptions = { | ||
}, { | ||
table_name: 'users_table', | ||
primary_key: 'id', | ||
engine: 'ReplicatedMergeTree()' | ||
} | ||
const schema = new ClickhouseSchema(schemaDefinition, options) | ||
}) | ||
const expectedQuery = 'CREATE TABLE IF NOT EXISTS users_table\n(\nid UUID,\nname String DEFAULT \'John Doe\',\nemail String\n)\nENGINE = ReplicatedMergeTree()\nPRIMARY KEY id' | ||
const query = schema.GetCreateTableQuery() | ||
console.log(query) | ||
expect(query).toEqual(expectedQuery) | ||
}) | ||
|
||
|
@@ -145,7 +146,7 @@ describe('ClickhouseSchema Tests', () => { | |
name: { type: ClickhouseTypes.CHString, default: 'John Doe' }, | ||
email: { type: ClickhouseTypes.CHString } | ||
} | ||
const options: ChSchemaOptions = { | ||
const options: ChSchemaOptions<typeof schemaDefinition> = { | ||
database: 'users_db', | ||
table_name: 'users_table', | ||
primary_key: 'id' | ||
|
@@ -162,7 +163,7 @@ describe('ClickhouseSchema Tests', () => { | |
name: { type: ClickhouseTypes.CHString, default: 'John Doe' }, | ||
email: { type: ClickhouseTypes.CHString } | ||
} | ||
const options: ChSchemaOptions = { | ||
const options: ChSchemaOptions<typeof schemaDefinition> = { | ||
table_name: 'users_table', | ||
primary_key: 'id', | ||
on_cluster: 'users_cluster', | ||
|
@@ -192,7 +193,7 @@ describe('ClickhouseSchema Tests', () => { | |
name: { type: ClickhouseTypes.CHString, default: 'John Doe' }, | ||
email: { type: ClickhouseTypes.CHString } | ||
} | ||
const options: ChSchemaOptions = { | ||
const options: ChSchemaOptions<typeof schemaDefinition> = { | ||
table_name: 'users_table', | ||
primary_key: 'id', | ||
on_cluster: 'users_cluster', | ||
|