Skip to content

Commit

Permalink
feat: rename method getExpiredRange to expiredRange
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The method `getExpiredRange` has been renamed to `expiredRange`. Update any usage of the old method name accordingly.
  • Loading branch information
vwh committed Jan 3, 2025
1 parent e991683 commit 13070f5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ const firstUsersPage = db.pagination(10, 1, "user:%");
const secondUsersPage = db.pagination(10, 2, "user:%");
```

### `getExpiredRange`
### `expiredRange`

Returns an array of keys that have expired between the given start and end dates.

Expand All @@ -377,13 +377,9 @@ Returns an array of keys that have expired between the given start and end dates
- **Returns**:
- The result of the operation, includes an array of keys or an error if the operation failed.


```ts
// Get the expired keys between two dates
const result = db.getExpiredRange(
new Date("2023-01-01"),
new Date("2023-01-31")
);
const result = db.expiredRange(new Date("2023-01-01"), new Date("2023-01-31"));

if (result.success) {
console.log(result.data);
Expand Down
Binary file modified bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export abstract class BaseMiftahDB implements IMiftahDB {
setExpire: this.db.prepare(SQL_STATEMENTS.SET_EXPIRE),
keys: this.db.prepare(SQL_STATEMENTS.KEYS),
pagination: this.db.prepare(SQL_STATEMENTS.PAGINATION),
getExpiredRange: this.db.prepare(SQL_STATEMENTS.GET_EXPIRED_RANGE),
expiredRange: this.db.prepare(SQL_STATEMENTS.GET_EXPIRED_RANGE),
cleanup: this.db.prepare(SQL_STATEMENTS.CLEANUP),
countKeys: this.db.prepare(SQL_STATEMENTS.COUNT_KEYS),
countExpired: this.db.prepare(SQL_STATEMENTS.COUNT_EXPIRED),
Expand Down Expand Up @@ -208,15 +208,15 @@ export abstract class BaseMiftahDB implements IMiftahDB {
}

@SafeExecution
getExpiredRange(
expiredRange(
start: Date | number,
end: Date | number,
pattern = "%"
): Result<string[]> {
const startDate = getExpireDate(start);
const endDate = getExpireDate(end);

const result = this.statements.getExpiredRange.all(
const result = this.statements.expiredRange.all(
this.addNamespacePrefix(pattern),
startDate,
endDate
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ export interface IMiftahDB<T extends MiftahValue = MiftahValue> {
* @returns {Result<string[]>} An array of expired keys.
* @example
* // Get the expired keys between two dates
* const result = db.getExpiredRange(new Date("2023-01-01"), new Date("2023-01-31"));
* const result = db.expiredRange(new Date("2023-01-01"), new Date("2023-01-31"));
* if (result.success) {
* console.log(result.data);
* } else {
* console.error(result.error);
* }
*/
getExpiredRange(
expiredRange(
start: Date | number,
end: Date | number,
pattern?: string
Expand Down
8 changes: 4 additions & 4 deletions tests/bun.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ test("Pagination", () => {
}
});

test("getExpiredRange", () => {
test("expiredRange", () => {
const db = createDB();
db.set("key1", "value1", new Date("2023-01-01"));
db.set("key2", "value2", new Date("2023-01-02"));
db.set("key3", "value3", new Date("2023-01-03"));
db.set("key4", "value4", new Date("2023-01-04"));
db.set("key5", "value5", new Date("2023-01-05"));

const result = db.getExpiredRange(
const result = db.expiredRange(
new Date("2023-01-02"),
new Date("2023-01-04")
);
Expand Down Expand Up @@ -348,7 +348,7 @@ test("Namespace Keys/Pagination", () => {
}
});

test("Namespace getExpiredRange", () => {
test("Namespace expiredRange", () => {
const db = createDB();
const users = db.namespace("users");
users.set("123", "value1", new Date("2023-01-01"));
Expand All @@ -357,7 +357,7 @@ test("Namespace getExpiredRange", () => {
users.set("101", "value4", new Date("2023-01-04"));
users.set("135", "value5", new Date("2023-01-05"));

const result = users.getExpiredRange(
const result = users.expiredRange(
new Date("2023-01-02"),
new Date("2023-01-04")
);
Expand Down
8 changes: 4 additions & 4 deletions tests/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ describe("MiftahDB Node Tests", () => {
}
});

it("getExpiredRange", () => {
it("expiredRange", () => {
const db = createDB();
db.set("key1", "value1", new Date("2023-01-01"));
db.set("key2", "value2", new Date("2023-01-02"));
db.set("key3", "value3", new Date("2023-01-03"));
db.set("key4", "value4", new Date("2023-01-04"));
db.set("key5", "value5", new Date("2023-01-05"));

const result = db.getExpiredRange(
const result = db.expiredRange(
new Date("2023-01-02"),
new Date("2023-01-04")
);
Expand Down Expand Up @@ -353,7 +353,7 @@ describe("MiftahDB Node Tests", () => {
}
});

it("Namespace getExpiredRange", () => {
it("Namespace expiredRange", () => {
const db = createDB();
const users = db.namespace("users");
users.set("123", "value1", new Date("2023-01-01"));
Expand All @@ -362,7 +362,7 @@ describe("MiftahDB Node Tests", () => {
users.set("101", "value4", new Date("2023-01-04"));
users.set("135", "value5", new Date("2023-01-05"));

const result = users.getExpiredRange(
const result = users.expiredRange(
new Date("2023-01-02"),
new Date("2023-01-04")
);
Expand Down

0 comments on commit 13070f5

Please sign in to comment.