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

Bug: expireAfterSeconds 0 can't be passed to Index decorator #5004

Closed
enten opened this issue Oct 31, 2019 · 0 comments
Closed

Bug: expireAfterSeconds 0 can't be passed to Index decorator #5004

enten opened this issue Oct 31, 2019 · 0 comments

Comments

@enten
Copy link
Contributor

enten commented Oct 31, 2019

Issue type:

[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[x] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

Currently, expireAfterSeconds: 0 can't be passed to Index decorator:

import { Column, Entity, Index, getMetadataArgsStorage } from 'typeorm';

@Entity()
export class Foo {
  @Column('date')
  @Index({ expireAfterSeconds: 0 })
  expireAt: Date;
}

console.log(getMetadataArgsStorage().indices);
/*
[ { target: [Function: Foo],
  name: undefined,
  columns: [ 'expireAt' ],
  synchronize: true,
  where: undefined,
  unique: false,
  spatial: false,
  fulltext: false,
  sparse: false,
  background: false,
  expireAfterSeconds: undefined } ]
*/

We can fix that with one line change:

diff --git a/src/decorator/Index.ts b/src/decorator/Index.ts
index 7b6197b..45683a5 100644
--- a/src/decorator/Index.ts
+++ b/src/decorator/Index.ts
@@ -79,7 +79,7 @@ export function Index(nameOrFieldsOrOptions?: string|string[]|((object: any) =>
             fulltext: options && options.fulltext ? true : false,
             sparse: options && options.sparse ? true : false,
             background: options && options.background ? true : false,
-            expireAfterSeconds: options && options.expireAfterSeconds ? options.expireAfterSeconds : undefined
+            expireAfterSeconds: options ? options.expireAfterSeconds : undefined
         } as IndexMetadataArgs);
     };
 }

I will make a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant