-
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.
Bugfix/default values incorrectly seralized (#20)
* fix * fixes * nullable type default value fix
- Loading branch information
1 parent
04e17c1
commit 17b8eb3
Showing
6 changed files
with
54 additions
and
41 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,8 +1,8 @@ | ||
import { type ClickhouseSchema } from '@clickhouse-schema-core/clickhouse_schema' | ||
import { type ChSchemaDefinition, type ClickhouseSchema } from '@clickhouse-schema-core/clickhouse_schema' | ||
import { type ChDataType } from '@clickhouse-schema-data-types/index' | ||
|
||
/** Infer is a type that takes a ChDataType and returns the typescript that it represents */ | ||
type Infer<T extends ChDataType> = T['typeScriptType'] | ||
|
||
/** InferSchemaClickhouseSchemaType is a type that takes a ClickhouseSchema and returns the typescript that it represents */ | ||
export type InferClickhouseSchemaType<T extends ClickhouseSchema<any>> = { [K in keyof T['schema']]: Infer<T['schema'][K]['type']> } | ||
export type InferClickhouseSchemaType<T extends ClickhouseSchema<ChSchemaDefinition>> = { [K in keyof T['schema']]: Infer<T['schema'][K]['type']> } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,11 @@ describe('ClickhouseSchema Tests', () => { | |
it('should correctly store schema definitions and options', () => { | ||
const schemaDefinition = { | ||
id: { type: ClickhouseTypes.CHUInt128() }, | ||
|
||
ch_json: { type: ClickhouseTypes.CHJSON({ k: { type: ClickhouseTypes.CHString() }, arr: { type: ClickhouseTypes.CHArray(ClickhouseTypes.CHJSON({ nested: { type: ClickhouseTypes.CHString() } })) } }) } | ||
} | ||
const options: ChSchemaOptions<typeof schemaDefinition> = { | ||
primary_key: 'id', | ||
order_by: 'id', | ||
table_name: 'users_table', | ||
engine: 'ReplicatedMergeTree()' | ||
} | ||
|
@@ -51,7 +51,7 @@ describe('ClickhouseSchema Tests', () => { | |
} | ||
|
||
const schema = new ClickhouseSchema(schemaDefinition, options) | ||
const expectedQuery = 'CREATE TABLE IF NOT EXISTS users_table\n(\nid UUID,\nname String,\nemail String,\nage UInt8\n)\nENGINE = MergeTree()\nPRIMARY KEY id' | ||
const expectedQuery = 'CREATE TABLE IF NOT EXISTS users_table\n(\nid UUID,\nname String,\nemail String,\nage UInt8\n)\nENGINE = MergeTree()\nPRIMARY KEY id;' | ||
const query = schema.GetCreateTableQuery() | ||
expect(query).toEqual(expectedQuery) | ||
}) | ||
|
@@ -69,7 +69,7 @@ describe('ClickhouseSchema Tests', () => { | |
} | ||
|
||
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 DEFAULT \'[email protected]\',\nage UInt8\n)\nENGINE = MergeTree()\nPRIMARY KEY id' | ||
const expectedQuery = 'CREATE TABLE IF NOT EXISTS users_table\n(\nid UUID,\nname String DEFAULT \'John Doe\',\nemail String DEFAULT \'[email protected]\',\nage UInt8\n)\nENGINE = MergeTree()\nPRIMARY KEY id;' | ||
const query = schema.GetCreateTableQuery() | ||
expect(query).toEqual(expectedQuery) | ||
}) | ||
|
@@ -87,7 +87,7 @@ describe('ClickhouseSchema Tests', () => { | |
additional_options: ['COMMENT \'This table provides user details\''] | ||
} | ||
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 DEFAULT \'[email protected]\',\nage UInt8 DEFAULT 18\n)\nENGINE = MergeTree()\nPRIMARY KEY id\nCOMMENT \'This table provides user details\'' | ||
const expectedQuery = 'CREATE TABLE IF NOT EXISTS users_table\n(\nid UUID,\nname String DEFAULT \'John Doe\',\nemail String DEFAULT \'[email protected]\',\nage UInt8 DEFAULT 18\n)\nENGINE = MergeTree()\nPRIMARY KEY id\nCOMMENT \'This table provides user details\';' | ||
const query = schema.GetCreateTableQuery() | ||
expect(query).toEqual(expectedQuery) | ||
}) | ||
|
@@ -103,7 +103,7 @@ describe('ClickhouseSchema Tests', () => { | |
order_by: 'id' | ||
} | ||
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 = MergeTree()\nORDER BY id' | ||
const expectedQuery = 'CREATE TABLE IF NOT EXISTS users_table\n(\nid UUID,\nname String DEFAULT \'John Doe\',\nemail String\n)\nENGINE = MergeTree()\nORDER BY id;' | ||
const query = schema.GetCreateTableQuery() | ||
expect(query).toEqual(expectedQuery) | ||
}) | ||
|
@@ -120,7 +120,7 @@ describe('ClickhouseSchema Tests', () => { | |
on_cluster: 'users_cluster' | ||
} | ||
const schema = new ClickhouseSchema(schemaDefinition, options) | ||
const expectedQuery = 'CREATE TABLE IF NOT EXISTS users_table ON CLUSTER users_cluster\n(\nid UUID,\nname String DEFAULT \'John Doe\',\nemail String\n)\nENGINE = MergeTree()\nPRIMARY KEY id' | ||
const expectedQuery = 'CREATE TABLE IF NOT EXISTS users_table ON CLUSTER users_cluster\n(\nid UUID,\nname String DEFAULT \'John Doe\',\nemail String\n)\nENGINE = MergeTree()\nPRIMARY KEY id;' | ||
const query = schema.GetCreateTableQuery() | ||
expect(query).toEqual(expectedQuery) | ||
}) | ||
|
@@ -135,7 +135,7 @@ describe('ClickhouseSchema Tests', () => { | |
primary_key: 'id', | ||
engine: 'ReplicatedMergeTree()' | ||
}) | ||
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 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() | ||
expect(query).toEqual(expectedQuery) | ||
}) | ||
|
@@ -152,7 +152,7 @@ describe('ClickhouseSchema Tests', () => { | |
primary_key: 'id' | ||
} | ||
const schema = new ClickhouseSchema(schemaDefinition, options) | ||
const expectedQuery = 'CREATE TABLE IF NOT EXISTS users_db.users_table\n(\nid UUID,\nname String DEFAULT \'John Doe\',\nemail String\n)\nENGINE = MergeTree()\nPRIMARY KEY id' | ||
const expectedQuery = 'CREATE TABLE IF NOT EXISTS users_db.users_table\n(\nid UUID,\nname String DEFAULT \'John Doe\',\nemail String\n)\nENGINE = MergeTree()\nPRIMARY KEY id;' | ||
const query = schema.GetCreateTableQuery() | ||
expect(query).toEqual(expectedQuery) | ||
}) | ||
|
@@ -181,7 +181,7 @@ describe('ClickhouseSchema Tests', () => { | |
'ENGINE = MergeTree()', | ||
'ORDER BY id', | ||
'PRIMARY KEY id', | ||
'COMMENT \'This table provides user details\'' | ||
'COMMENT \'This table provides user details\';' | ||
] | ||
const query = schema.GetCreateTableQueryAsList() | ||
expect(query).toEqual(expectedQuery) | ||
|
@@ -201,26 +201,30 @@ describe('ClickhouseSchema Tests', () => { | |
additional_options: ['COMMENT \'This table provides user details\''] | ||
} | ||
const schema = new ClickhouseSchema(schemaDefinition, options) | ||
const expectedQuery = 'CREATE TABLE IF NOT EXISTS users_table ON CLUSTER users_cluster\n(\nid UUID,\nname String DEFAULT \'John Doe\',\nemail String\n)\nENGINE = MergeTree()\nORDER BY id\nPRIMARY KEY id\nCOMMENT \'This table provides user details\'' | ||
const expectedQuery = 'CREATE TABLE IF NOT EXISTS users_table ON CLUSTER users_cluster\n(\nid UUID,\nname String DEFAULT \'John Doe\',\nemail String\n)\nENGINE = MergeTree()\nORDER BY id\nPRIMARY KEY id\nCOMMENT \'This table provides user details\';' | ||
// eslint-disable-next-line @typescript-eslint/no-base-to-string | ||
const query = schema.toString() | ||
|
||
expect(query).toEqual(expectedQuery) | ||
}) | ||
|
||
it('should not throw if on_cluster is specified but primary_key or order_by is not', () => { | ||
const schemaDefinition = { | ||
id: { type: ClickhouseTypes.CHUUID() }, | ||
name: { type: ClickhouseTypes.CHString('John Doe') }, | ||
email: { type: ClickhouseTypes.CHString() } | ||
try { | ||
const schemaDefinition = { | ||
id: { type: ClickhouseTypes.CHUUID() }, | ||
name: { type: ClickhouseTypes.CHString('John Doe') }, | ||
email: { type: ClickhouseTypes.CHString() } | ||
} | ||
const options: ChSchemaOptions<typeof schemaDefinition> = { | ||
table_name: 'users_table', | ||
on_cluster: 'users_cluster' | ||
} | ||
const schema = new ClickhouseSchema(schemaDefinition, options) | ||
const expectedQuery = 'CREATE TABLE IF NOT EXISTS users_table ON CLUSTER users_cluster\n(\nid UUID,\nname String DEFAULT \'John Doe\',\nemail String\n)\nENGINE = MergeTree();' | ||
const query = schema.GetCreateTableQuery() | ||
expect(query).toEqual(expectedQuery) | ||
} catch (e) { | ||
console.log(e, 'hereeeeeee') | ||
} | ||
const options: ChSchemaOptions<typeof schemaDefinition> = { | ||
table_name: 'users_table', | ||
on_cluster: 'users_cluster' | ||
} | ||
const schema = new ClickhouseSchema(schemaDefinition, options) | ||
const expectedQuery = 'CREATE TABLE IF NOT EXISTS users_table ON CLUSTER users_cluster\n(\nid UUID,\nname String DEFAULT \'John Doe\',\nemail String\n)\nENGINE = MergeTree()' | ||
const query = schema.GetCreateTableQuery() | ||
expect(query).toEqual(expectedQuery) | ||
}) | ||
}) |
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
17b8eb3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report
Test suite run success
25 tests passing in 2 suites.
Report generated by 🧪jest coverage report action from 17b8eb3