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

Adding expires defaultExpires function #452

Merged
merged 1 commit into from
Oct 22, 2018
Merged

Adding expires defaultExpires function #452

merged 1 commit into from
Oct 22, 2018

Conversation

fishcharlie
Copy link
Member

@fishcharlie fishcharlie commented Oct 22, 2018

Summary:

This PR adds support for a defaultExpires property within the expires option.

Code sample:

Schema

 var schema = new Schema({...}, {
  expires: {
    ttl: 7*24*60*60, // 1 week in seconds
    attribute: 'ttl', // ttl will be used as the attribute name
    returnExpiredItems: true // if expired items will be returned or not (default: true)
    returnExpiredItems: true, // if expired items will be returned or not (default: true)
    defaultExpires: function () { // optional, will default to `ttl` if not defined, this function is mainly used to allow the expires to be set to null or undefined, without resetting to the normal default
      // this code will be run if `ttl` is undefined or null
      return null;
    }
  }
});

General

var item = new Item();
item.title = "Hello World";
item.expires = new Date(new Date().getTime() + (1000 * 60 * 60 * 24 * 365));
item.save(function (err, itemB) {
  itemB.expires = null;
  itemB.save(function () {
    Item.get("Hello World", function (err, itemC) {
      console.log(itemC.expires); // null

      // Normally `itemC.expires` would have been reset back to the default `ttl` which in this case is (7*24*60*60)
      // But since we override the `defaultExpires` property that function will be run since `itemB.expires` was set to null
      // And that function returns null, so it will keep it's null value.
    });
  });
});

Type (select 1):

  • Bug fix
  • Feature implementation
  • Documentation improvement
  • Testing improvement
  • Test added to report bug (GitHub issue #--- @---)
  • Something not listed here

Is this a breaking change? (select 1):

  • 🚨 YES 🚨
  • No
  • I'm not sure

Is this ready to be merged into Dynamoose? (select 1):

  • Yes
  • No

Are all the tests currently passing on this PR? (select 1):

  • Yes
  • No

Other:

  • I have searched through the GitHub pull requests to ensure this PR has not already been submitted
  • I have updated the Dynamoose documentation (if required) given the changes I made
  • I have added/updated the Dynamoose test cases (if required) given the changes I made
  • I have run npm test from the root of the project directory to ensure all tests continue to pass
  • I agree that all changes made in this pull request may be distributed and are made available in accordance with the Dynamoose license
  • All of my commits and commit messages are detailed, explain what changes were made, and are easy to follow and understand
  • I have confirmed that all my code changes are indented properly using 2 spaces
  • I have filled out all fields above

@coveralls
Copy link

coveralls commented Oct 22, 2018

Pull Request Test Coverage Report for Build 694

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.03%) to 85.186%

Files with Coverage Reduction New Missed Lines %
lib/index.js 3 89.02%
Totals Coverage Status
Change from base Build 692: 0.03%
Covered Lines: 1881
Relevant Lines: 2140

💛 - Coveralls

@fishcharlie fishcharlie mentioned this pull request Oct 22, 2018
@fishcharlie fishcharlie merged commit 68048ae into dynamoose:master Oct 22, 2018
@fishcharlie fishcharlie deleted the expiresImprovements branch October 22, 2018 20:14
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

Successfully merging this pull request may close these issues.

2 participants