Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
good-lly committed Mar 6, 2024
1 parent e184d93 commit dfe3d06
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const newUser = await usersCol.insert({
posts: [],
});

// Find users with pagination (e.g., page 2, 10 users per page)
const secondPageUsers = await usersCol.find().skip(10).limit(10);

// Show all users
const allUsers = usersCol.find({});

Expand Down Expand Up @@ -101,6 +104,10 @@ Check out [wrangler.toml from examples](https://github.com/good-lly/lowstorage/b
- **Behavior**: Searches for documents that match the query.
- **Returns**: A promise that resolves to an array of matching documents.

- **_skip(numToSkip)_** Skips the specified number of documents in query results. Use this for pagination (e.g., skipping the first page of results). Returns the updated collection instance to allow chaining.

- **_limit(numToLimit)_** Limits the number of documents returned by query results. Use this for pagination (e.g., limiting to 10 results per page). Returns the updated collection instance to allow chaining.

- **findOne(query)**

- **Input**: A query object.
Expand Down
26 changes: 13 additions & 13 deletions src/lowstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ const _generateUUID = () => {
};

const _isR2Store = (obj) => {
let hasMethod = (obj, name) => {
return typeof obj !== 'undefined' && obj !== null && typeof obj[name] === 'function';
};

return (
typeof obj === 'object' &&
obj !== null &&
'get' in obj &&
typeof obj.get === 'function' &&
'put' in obj &&
typeof obj.put === 'function' &&
'delete' in obj &&
typeof obj.delete === 'function' &&
'list' in obj &&
typeof obj.list === 'function'
hasMethod(obj, 'get') &&
hasMethod(obj, 'put') &&
hasMethod(obj, 'delete') &&
hasMethod(obj, 'list')
);
};

const _getStore = (env, storeName) => {
let store = storeName ? env[storeName] ?? null : null;
let store = storeName ? env[storeName] : null;
if (!store) {
// Check for null directly
for (const obj of Object.values(env)) {
Expand Down Expand Up @@ -134,12 +134,12 @@ class Collection {
const data = await this._loadData();
let updatedCount = 0;

data.forEach((doc) => {
if (_matchesQuery(doc, query)) {
Object.assign(doc, update);
for (let i = 0; i < data.length; i++) {
if (_matchesQuery(data[i], query)) {
Object.assign(data[i], update);
updatedCount++;
}
});
}

if (updatedCount > 0) {
await this._saveData(data);
Expand Down

0 comments on commit dfe3d06

Please sign in to comment.