Skip to content

Commit

Permalink
document functions and classes (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit-kadhe authored Mar 27, 2024
1 parent ec98d79 commit 95efb86
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 12 deletions.
17 changes: 16 additions & 1 deletion core/clickhouse_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@ export interface ChSchemaOptions<T> {
additional_options?: string[]
}

/**
* IClickhouseSchema is an interface that represents a clickhouse schema.
*/
interface IClickhouseSchema<T> {
GetOptions: () => ChSchemaOptions<T>
GetCreateTableQuery: () => string
GetCreateTableQueryAsList: () => string[]
}

/* This class is used to represent a clickhouse table schema */
/**
* ClickhouseSchema is a class that represents a clickhouse schema.
* @param schema is the schema definition
* @param options is the options for the schema
*/
export class ClickhouseSchema<SchemaDefinition extends ChSchemaDefinition> implements IClickhouseSchema<SchemaDefinition> {
readonly schema: SchemaDefinition
private readonly options: ChSchemaOptions<SchemaDefinition>
Expand Down Expand Up @@ -75,10 +82,18 @@ export class ClickhouseSchema<SchemaDefinition extends ChSchemaDefinition> imple
return createTableQuery
}

/**
*
* @returns the create table query as a list of strings
*/
GetCreateTableQueryAsList (): string[] {
return this.GetCreateTableQuery().split('\n')
}

/**
*
* @returns the create table query as a string
*/
toString (): string {
return this.GetCreateTableQuery()
}
Expand Down
4 changes: 4 additions & 0 deletions data_types/ch_array.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { type ChDataType } from '@clickhouse-schema-data-types/index'

/**
* ChArray is a class that represents an array of a Clickhouse data type
* @param T - The type of the array elements (can be a ChDataType or another ChArray)
*/
export class ChArray<T extends ChDataType | ChArray<ChDataType>> implements ChDataType {
readonly innerType: T
readonly typeStr: string
Expand Down
3 changes: 3 additions & 0 deletions data_types/ch_boolean.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { type ChDataType } from '@clickhouse-schema-data-types/index'

/**
* ChBoolean is a class that represents a Clickhouse Boolean data type
*/
export class ChBoolean implements ChDataType {
readonly typeStr: 'Boolean' = 'Boolean' as const

Expand Down
14 changes: 14 additions & 0 deletions data_types/ch_date.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { type ChDataType } from '@clickhouse-schema-data-types/index'

/**
* ChDate is a class that represents a Clickhouse Date data type
*/
export class ChDate implements ChDataType {
readonly typeStr: 'Date' = 'Date' as const

Expand All @@ -8,6 +11,9 @@ export class ChDate implements ChDataType {
}
}

/**
* ChDate32 is a class that represents a Clickhouse Date32 data type
*/
export class ChDate32 implements ChDataType {
readonly typeStr: 'Date32' = 'Date32' as const

Expand All @@ -16,6 +22,9 @@ export class ChDate32 implements ChDataType {
}
}

/**
* ChDate64 is a class that represents a Clickhouse Date64 data type
*/
export class ChDateTime<T extends string> implements ChDataType {
readonly typeStr: `DateTime('${T}')`

Expand All @@ -28,6 +37,11 @@ export class ChDateTime<T extends string> implements ChDataType {
}
}

/**
* ChDateTime64 is a class that represents a Clickhouse DateTime64 data type
* @param T - The precision of the DateTime64
* @param V - The timezone of the DateTime64
*/
export class ChDateTime64<T extends number, V extends string> implements ChDataType {
readonly typeStr: `DateTime64(${T}, '${V}')`

Expand Down
5 changes: 5 additions & 0 deletions data_types/ch_decimal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { type ChDataType } from '@clickhouse-schema-data-types/index'

/**
* ChDecimal is a class that represents a Clickhouse Decimal data type
* @param P - The precision of the Decimal
* @param S - The scale of the Decimal
*/
export class ChDecimal<P extends number, S extends number> implements ChDataType {
readonly typeStr: `Decimal(${P},${S})`

Expand Down
7 changes: 6 additions & 1 deletion data_types/ch_float.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { type ChDataType } from '@clickhouse-schema-data-types/index'

/**
* ChFloat32 is a class that represents a Clickhouse Float32 data type
*/
export class ChFloat32 implements ChDataType {
readonly typeStr: 'Float32' = 'Float32' as const

toString (): string {
return this.typeStr
}
}

/**
* ChFloat64 is a class that represents a Clickhouse Float64 data type
*/
export class ChFloat64 implements ChDataType {
readonly typeStr: 'Float64' = 'Float64' as const

Expand Down
37 changes: 37 additions & 0 deletions data_types/ch_integer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { type ChDataType } from '@clickhouse-schema-data-types/index'

/**
* ChUInt8 is a class that represents a Clickhouse UInt8 data type
*/
export class ChUInt8 implements ChDataType {
readonly typeStr: 'UInt8' = 'UInt8' as const

Expand All @@ -12,6 +15,9 @@ export class ChUInt8 implements ChDataType {
}
}

/**
* ChUInt16 is a class that represents a Clickhouse UInt16 data type
*/
export class ChUInt16 implements ChDataType {
readonly typeStr: 'UInt16' = 'UInt16' as const

Expand All @@ -24,6 +30,9 @@ export class ChUInt16 implements ChDataType {
}
}

/**
* ChUInt32 is a class that represents a Clickhouse UInt32 data type
*/
export class ChUInt32 implements ChDataType {
readonly typeStr: 'UInt32' = 'UInt32' as const

Expand All @@ -32,6 +41,9 @@ export class ChUInt32 implements ChDataType {
}
}

/**
* ChUInt64 is a class that represents a Clickhouse UInt64 data type
*/
export class ChUInt64 implements ChDataType {
readonly typeStr: 'UInt64' = 'UInt64' as const

Expand All @@ -40,6 +52,9 @@ export class ChUInt64 implements ChDataType {
}
}

/**
* ChUInt128 is a class that represents a Clickhouse UInt128 data type
*/
export class ChUInt128 implements ChDataType {
readonly typeStr: 'UInt128' = 'UInt128' as const

Expand All @@ -48,6 +63,9 @@ export class ChUInt128 implements ChDataType {
}
}

/**
* ChUInt256 is a class that represents a Clickhouse UInt256 data type
*/
export class ChUInt256 implements ChDataType {
readonly typeStr: 'UInt256' = 'UInt256' as const

Expand All @@ -56,6 +74,9 @@ export class ChUInt256 implements ChDataType {
}
}

/**
* ChInt8 is a class that represents a Clickhouse Int8 data type
*/
export class ChInt8 implements ChDataType {
readonly typeStr: 'Int8' = 'Int8' as const

Expand All @@ -64,6 +85,10 @@ export class ChInt8 implements ChDataType {
}
}

/**
* ChInt16 is a class that represents a Clickhouse Int16 data type
*/
export class ChInt16 implements ChDataType {
readonly typeStr: 'Int16' = 'Int16' as const

Expand All @@ -72,6 +97,9 @@ export class ChInt16 implements ChDataType {
}
}

/**
* ChInt32 is a class that represents a Clickhouse Int32 data type
*/
export class ChInt32 implements ChDataType {
readonly typeStr: 'Int32' = 'Int32' as const

Expand All @@ -80,6 +108,9 @@ export class ChInt32 implements ChDataType {
}
}

/**
* ChInt64 is a class that represents a Clickhouse Int64 data type
*/
export class ChInt64 implements ChDataType {
readonly typeStr: 'Int64' = 'Int64' as const

Expand All @@ -88,6 +119,9 @@ export class ChInt64 implements ChDataType {
}
}

/**
* ChInt128 is a class that represents a Clickhouse Int128 data type
*/
export class ChInt128 implements ChDataType {
readonly typeStr: 'Int128' = 'Int128' as const

Expand All @@ -96,6 +130,9 @@ export class ChInt128 implements ChDataType {
}
}

/**
* ChInt256 is a class that represents a Clickhouse Int256 data type
*/
export class ChInt256 implements ChDataType {
readonly typeStr: 'Int256' = 'Int256' as const

Expand Down
3 changes: 3 additions & 0 deletions data_types/ch_json.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { type ChSchemaDefinition } from '@clickhouse-schema-core/clickhouse_schema'
import { type ChDataType } from '@clickhouse-schema-data-types/index'

/**
* ChJSON is a class that represents a Clickhouse JSON data type
*/
export class ChJSON<T extends ChSchemaDefinition> implements ChDataType {
readonly typeStr: 'JSON'
readonly innerType: T
Expand Down
7 changes: 7 additions & 0 deletions data_types/ch_low_ cardinality.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { type ChDataType } from '@clickhouse-schema-data-types/index'

/**
* ChEnum is a class that represents a Clickhouse Enum data type
* @param T - The enum object. The keys are the enum names and the values are the enum values
*/
export class ChEnum<T extends Record<string, number>> implements ChDataType {
readonly typeStr: string
readonly innerType: T
Expand All @@ -14,6 +18,9 @@ export class ChEnum<T extends Record<string, number>> implements ChDataType {
}
}

/**
* ChLowCardinality is a class that represents a Clickhouse LowCardinality data type
*/
export class ChLowCardinality<T extends ChDataType> implements ChDataType {
readonly typeStr

Expand Down
4 changes: 4 additions & 0 deletions data_types/ch_nullable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { type ChPrimitiveType, type ChDataType } from '@clickhouse-schema-data-types/index'

/**
* ChNullable is a class that represents a Clickhouse Nullable data type
* @param T - The inner type of the Nullable. Must be a primitive type
*/
export class ChNullable<T extends ChPrimitiveType> implements ChDataType {
readonly typeStr
readonly innerType: T
Expand Down
7 changes: 7 additions & 0 deletions data_types/ch_string.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { type ChDataType } from '@clickhouse-schema-data-types/index'

/**
* ChString is a class that represents a Clickhouse String data type
*/
export class ChString implements ChDataType {
readonly typeStr: 'String' = 'String' as const

Expand All @@ -8,6 +11,10 @@ export class ChString implements ChDataType {
}
}

/**
* ChFixedString is a class that represents a Clickhouse FixedString data type
* @param T - The length of the FixedString
*/
export class ChFixedString<T extends number> implements ChDataType {
readonly typeStr: `FixedString(${T})`

Expand Down
3 changes: 3 additions & 0 deletions data_types/ch_uuid.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { type ChDataType } from '@clickhouse-schema-data-types/index'

/**
* ChUUID is a class that represents a Clickhouse UUID data type
*/
export class ChUUID implements ChDataType {
readonly typeStr: 'UUID' = 'UUID' as const

Expand Down
Loading

1 comment on commit 95efb86

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 100% 177/177
🟢 Branches 100% 25/25
🟢 Functions 100% 73/73
🟢 Lines 100% 155/155

Test suite run success

23 tests passing in 2 suites.

Report generated by 🧪jest coverage report action from 95efb86

Please sign in to comment.