Skip to content

Commit

Permalink
fix: projects might have strictPropertyInitialization set to true
Browse files Browse the repository at this point in the history
att
  • Loading branch information
cyjake committed Aug 24, 2022
1 parent 3430f46 commit 0387c47
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/bone.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const pluralize = require('pluralize');
const { executeValidator, LeoricValidateError } = require('./validator');
require('reflect-metadata');

const { DataTypes } = require('./data_types');
const { default: DataTypes } = require('./data_types');
const Collection = require('./collection');
const Spell = require('./spell');
const Raw = require('./raw');
Expand Down
46 changes: 19 additions & 27 deletions src/data_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,9 @@ export interface AbstractDataType<T> {
*/

export abstract class DataType {
dataType: string;
dataType: string = '';
dataLength?: string | number;

/**
* Check if params is instance of DataType or not
* @param {*} params
* @returns {boolean}
*/
static is(params: any): boolean {
return params instanceof DataType;
}

/**
* cast raw data returned from data packet into js type
*/
Expand All @@ -51,21 +42,7 @@ export abstract class DataType {
return value;
}

static get invokable() {
return new Proxy(this, {
get(target, p) {
const value = target[p];
if (AllDataTypes.hasOwnProperty(p)) return invokableFunc(value);
return value;
}
});
}

abstract toSqlString(): string;

static toSqlString(): string {
return '';
}
}

/**
Expand Down Expand Up @@ -507,7 +484,7 @@ const AllDataTypes = {

type DATA_TYPE<T> = AbstractDataType<T> & T;

export class DataTypes extends DataType {
class DataTypes {
static STRING: DATA_TYPE<STRING> = STRING as any;
static TINYINT: DATA_TYPE<TINYINT> = TINYINT as any;
static SMALLINT: DATA_TYPE<SMALLINT> = SMALLINT as any;
Expand Down Expand Up @@ -598,8 +575,23 @@ export class DataTypes extends DataType {
}
}

toSqlString(): string {
return '';
static get invokable() {
return new Proxy(this, {
get(target, p) {
const value = target[p];
if (AllDataTypes.hasOwnProperty(p)) return invokableFunc(value);
return value;
}
});
}

/**
* Check if params is instance of DataType or not
* @param {*} params
* @returns {boolean}
*/
static is(params: any): boolean {
return params instanceof DataType;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/mysql/data_types.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { DataTypes } = require('../../data_types');
const { default: DataTypes } = require('../../data_types');

class Mysql_BOOLEAN extends DataTypes.BOOLEAN {
constructor() {
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/postgres/data_types.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { DataTypes } = require('../../data_types');
const { default: DataTypes } = require('../../data_types');
const util = require('util');
const Raw = require('../../raw');

Expand Down Expand Up @@ -29,7 +29,7 @@ class Postgres_JSONB extends DataTypes.JSONB {
}
}

class Postgres_BINARY extends DataTypes {
class Postgres_BINARY extends DataTypes.BINARY {
constructor() {
super();
this.dataType = 'bytea';
Expand Down
3 changes: 2 additions & 1 deletion src/drivers/postgres/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ class PostgresDriver extends AbstractDriver {
for (const row of rows) {
const tableName = row.table_name;
const columns = schemaInfo[tableName] || (schemaInfo[tableName] = []);
let { data_type: dataType, character_maximum_length: length } = row;
const { character_maximum_length: length } = row;
let { data_type: dataType } = row;

if (dataType === 'character varying') dataType = 'varchar';
if (dataType === 'timestamp without time zone') dataType = 'timestamp';
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/sqlite/data_types.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { DataTypes } = require('../../data_types');
const { default: DataTypes } = require('../../data_types');

class Sqlite_DATE extends DataTypes.DATE {
constructor(precision, timezone) {
Expand Down Expand Up @@ -53,7 +53,7 @@ class Sqlite_BIGINT extends DataTypes.BIGINT {
return this.dataType.toUpperCase();
}
}
class Sqlite_BINARY extends DataTypes {
class Sqlite_BINARY extends DataTypes.BINARY {
constructor(dataLength = 255) {
super(dataLength);
this.dataLength = dataLength;
Expand Down

0 comments on commit 0387c47

Please sign in to comment.