Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ibmi): add database version compatibility check for native boolean + initial unit tests #16909

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions packages/core/src/dialects/ibmi/data-types.ts
Expand Up @@ -8,16 +8,27 @@ export class UUID extends BaseTypes.UUID {
}

export class BOOLEAN extends BaseTypes.BOOLEAN {
protected supportsNativeBooleans() {
Copy link
Member

Choose a reason for hiding this comment

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

this should be hard private

const databaseVersion
= Number.parseFloat(this._getDialect().sequelize.options.databaseVersion || this._getDialect().defaultVersion);
Copy link
Member

Choose a reason for hiding this comment

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

Don't get the database version like this, but via sequelize.getDatabaseVersion()


return databaseVersion >= 7.5;
Comment on lines +12 to +15
Copy link
Member

Choose a reason for hiding this comment

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

We can use the gt function from semver to compare this to getDatabaseVersion()

}

escape(value: boolean | Falsy): string {
return value ? '1' : '0';
return this.supportsNativeBooleans() ? super.escape(value) : value ? '1' : '0';
}

parseDatabaseValue(value: unknown): boolean {
return this.supportsNativeBooleans() ? value === 'TRUE' : value === 1;
}

toBindableValue(value: boolean | Falsy): unknown {
return value ? 1 : 0;
return this.supportsNativeBooleans() ? super.toBindableValue(value) : value ? 1 : 0;
}

toSql() {
return 'SMALLINT';
return this.supportsNativeBooleans() ? super.toSql() : 'SMALLINT';
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/dialects/ibmi/index.ts
Expand Up @@ -38,6 +38,7 @@ export class IBMiDialect extends AbstractDialect {
changeSchema: false,
changeSchemaAndTable: false,
},
finalTable: true,
},
);

Expand Down
Expand Up @@ -178,7 +178,7 @@ export class IBMiQueryGeneratorTypeScript extends AbstractQueryGenerator {

// Version queries
versionQuery() {
return 'SELECT CONCAT(OS_VERSION, CONCAT(\'.\', OS_RELEASE)) AS "version" FROM SYSIBMADM.ENV_SYS_INFO';
return `SELECT CONCAT(OS_VERSION, CONCAT('.', OS_RELEASE)) AS "version" FROM SYSIBMADM.ENV_SYS_INFO`;
}

tableExistsQuery(tableName: TableNameOrModel): string {
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/dialects/ibmi/query-generator.js
Expand Up @@ -335,7 +335,6 @@ export class IBMiQueryGenerator extends IBMiQueryGeneratorTypeScript {
const query = super.insertQuery(table, valueHash, modelAttributes, options);
if (query.query.at(-1) === ';') {
query.query = query.query.slice(0, -1);
query.query = `SELECT * FROM FINAL TABLE (${query.query})`;
}

return query;
Expand All @@ -356,7 +355,6 @@ export class IBMiQueryGenerator extends IBMiQueryGeneratorTypeScript {
let query = super.bulkInsertQuery(tableName, fieldValueHashes, options, fieldMappedAttributes);
if (query.at(-1) === ';') {
query = query.slice(0, -1);
query = `SELECT * FROM FINAL TABLE (${query})`;
Copy link
Member

Choose a reason for hiding this comment

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

why remove the "select from final table"? :o

}

return query;
Expand Down
1 change: 1 addition & 0 deletions packages/core/test/config/config.ts
Expand Up @@ -96,5 +96,6 @@ export const Config: Record<Dialect, Options> = {
dialectOptions: {
odbcConnectionString: env.SEQ_IBMI_CONN_STR,
},
databaseVersion: '7.3.0',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
databaseVersion: '7.3.0',

ibmi has a defaultVersion of 7.3.0 already

},
};