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

Use defaults provided in entity definition decorators #6846

Closed
Closed
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: 9 additions & 8 deletions src/query-builder/InsertQueryBuilder.ts
Expand Up @@ -472,17 +472,18 @@ export class InsertQueryBuilder<Entity> extends QueryBuilder<Entity> {

// if value for this column was not provided then insert default value
} else if (value === undefined) {
if (this.connection.driver instanceof AbstractSqliteDriver || this.connection.driver instanceof SapDriver) { // unfortunately sqlite does not support DEFAULT expression in INSERT queries
if (column.default !== undefined) { // try to use default defined in the column
expression += this.connection.driver.normalizeDefault(column);
if (column.default !== undefined) {
// if default value presented in the default property then use it
expression += this.connection.driver.normalizeDefault(column);
} else {
// otherwise use null for sqlite and sap (becauze these dbs not supported defaults in schema)
// of use default keyword for other databases
if (this.connection.driver instanceof AbstractSqliteDriver || this.connection.driver instanceof SapDriver) {
expression += "NULL";
} else {
expression += "NULL"; // otherwise simply use NULL and pray if column is nullable
expression += "DEFAULT";
}

} else {
expression += "DEFAULT";
}

// support for SQL expressions in queries
} else if (value instanceof Function) {
expression += value();
Expand Down