Skip to content

Commit

Permalink
update SingleStore decimal column type
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodriguespn committed Nov 11, 2024
1 parent e9db7f1 commit 7be73df
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions drizzle-orm/src/singlestore-core/columns/decimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ export class SingleStoreDecimalBuilder<
> extends SingleStoreColumnBuilderWithAutoIncrement<T, SingleStoreDecimalConfig> {
static override readonly [entityKind]: string = 'SingleStoreDecimalBuilder';

constructor(name: T['name'], precision?: number, scale?: number) {
constructor(name: T['name'], config: SingleStoreDecimalConfig | undefined) {
super(name, 'string', 'SingleStoreDecimal');
this.config.precision = precision;
this.config.scale = scale;
this.config.precision = config?.precision;
this.config.scale = config?.scale;
this.config.unsigned = config?.unsigned;
}

/** @internal */
Expand All @@ -44,21 +45,26 @@ export class SingleStoreDecimal<T extends ColumnBaseConfig<'string', 'SingleStor

readonly precision: number | undefined = this.config.precision;
readonly scale: number | undefined = this.config.scale;
readonly unsigned: boolean | undefined = this.config.unsigned;

getSQLType(): string {
let type = '';
if (this.precision !== undefined && this.scale !== undefined) {
return `decimal(${this.precision},${this.scale})`;
type += `decimal(${this.precision},${this.scale})`;
} else if (this.precision === undefined) {
return 'decimal';
type += 'decimal';
} else {
return `decimal(${this.precision})`;
type += `decimal(${this.precision})`;
}
type = type === 'decimal(10,0)' || type === 'decimal(10)' ? 'decimal' : type;
return this.unsigned ? `${type} unsigned` : type;
}
}

export interface SingleStoreDecimalConfig {
precision?: number;
scale?: number;
unsigned?: boolean;
}

export function decimal(): SingleStoreDecimalBuilderInitial<''>;
Expand All @@ -71,5 +77,5 @@ export function decimal<TName extends string>(
): SingleStoreDecimalBuilderInitial<TName>;
export function decimal(a?: string | SingleStoreDecimalConfig, b: SingleStoreDecimalConfig = {}) {
const { name, config } = getColumnNameAndConfig<SingleStoreDecimalConfig>(a, b);
return new SingleStoreDecimalBuilder(name, config.precision, config.scale);
return new SingleStoreDecimalBuilder(name, config);
}

0 comments on commit 7be73df

Please sign in to comment.