Skip to content

Commit

Permalink
Merge pull request #15 from klich3/master
Browse files Browse the repository at this point in the history
Other minor update
  • Loading branch information
klich3 authored Sep 10, 2024
2 parents b1b6503 + 8fcc124 commit b6063e6
Show file tree
Hide file tree
Showing 23 changed files with 185 additions and 42 deletions.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ If no key is given, an auto-incremented sequence is used as key.

If the function fails for any reason, an error is thrown.

---

### Get
Find and retrieve records, in a collection.
```javascript
Expand All @@ -140,6 +142,8 @@ __Return__ an array of
NB: wildcards are very expensive on large datasets with most filesystems.
(on a regular PC with +10^7 records in the collection, it might take up to a second to retreive one record, whereas one might retrieve up to 100.000 records with an exact key match)
---
### Delete
Delete one or more records, whos key match.
Expand Down Expand Up @@ -188,6 +192,7 @@ const rs = await store.Rocketstore({
|data_format | Specify which format the records are stored in. Values are: _FORMAT_NATIVE - default. and RS_FORMAT_JSON - Use JSON data format.|
|check_files | Specify how to strong check collection names. Values are: _FILECHECK_DEFAULT - default. and _FILECHECK_LOW - Simpler approach.|
---
## Examples
#### Storing records:
Expand Down Expand Up @@ -232,6 +237,7 @@ The above example will output this:
#### Inserting an auto inceremented key
File names must always be unique. If you have more than one instance of a file name, you can add an auto incremented sequence to the name:
```javascript
Expand Down Expand Up @@ -262,6 +268,7 @@ The above will output this:
}
#### Inserting with Globally Unique IDentifier key
Another option is to add a GUID to the key.
The GUID is a combination of a timestamp and a random sequence, formatet in accordance to RFC 4122 (Valid but slightly less random)
Expand Down Expand Up @@ -295,7 +302,6 @@ The above will output this:
]
}
#### Mass insterts
```javascript
const dataset = {
Expand Down Expand Up @@ -365,9 +371,11 @@ rs.delete("cars");
```javascript
rs.delete();
```
---
## File system issue
This was made with node ver 11. A compromise was struck, to compensate for the immaturity of the node file system library; There is no proper glob functionality, to filter a directory search on a low level. Instead, an array of all entries is read.
This consumes a lot of memory, with a large database. There is no avoiding that, short of improving opon the node file system library. This is beyond my intentions, at this time. I hope it will be remedied by the node core team.
Expand All @@ -382,6 +390,7 @@ Therefore a time consuming locking mecahnism is implemented as symlinks.
Both solutions will hopefully be changed, as node matures.
---
## Benchmarks
Benchmarks are performed with 1 million records in in a single collection.
Expand Down Expand Up @@ -409,20 +418,48 @@ Deleting test data if any
---
## Contributions
* I appreciate all kinds of contribution.
* Don't hesitate to submit an issue report on [github](https://github.com/paragi/rocket-store/issues). But please provide a reproducible example.
* Code should look good and compact, and be covered by a test case or example.
* Please don't change the formatting style laid out, without a good reason. I know its not the most common standard, but its rather efficient one.
---
## Build before publish
First run `npm install typescript -g` after thaht run `npm run build`.
---
## Examples
In the `examples` folder, there are two folders: ***CommonJS*** and ***Module***.
Enter one of them and run the command `npm i && npm run test`.
---
## Ported to other languages
> [!NOTE]
> The same mechanism is also ported to:
>
> ***PHP***: https://github.com/paragi/rocket-store
>
> ***Python***: https://github.com/klich3/rocket-store-python
---
## Updates
0.10.19
- Correct check_files type declaration
- Update README.md file - added links of Rocket Store ported to other languages
- Added correct examples by folders
0.10.18
- Added new Option for Check files names
Expand Down
2 changes: 1 addition & 1 deletion dist/cjs/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Author: Simon Riget
Contributor: <Anton Sychev> (anton at sychev dot xyz)
index.js (c) 2017 - 2023
index.js (c) 2017 - 20234
Created: 2023-10-28 02:12:56
Desc: Constants variables
License:
Expand Down
4 changes: 2 additions & 2 deletions dist/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Author: Simon Riget
Contributor: <Anton Sychev> (anton at sychev dot xyz)
index.js (c) 2017 - 2023
index.js (c) 2017 - 2024
Created: 2023-10-26 02:43:48
Desc: Rocket Store - A very simple and yet powerful file storage.
License:
Expand Down Expand Up @@ -131,7 +131,7 @@ Rocketstore.options = (...args_1) => __awaiter(void 0, [...args_1], void 0, func
if (typeof options.lock_files === "boolean")
Rocketstore.lock_files = options.lock_files;
// filecheck
if (typeof options.check_files === "boolean")
if (typeof options.check_files === "number")
Rocketstore.check_files = options.check_files;
});
/**
Expand Down
2 changes: 1 addition & 1 deletion dist/cjs/utils/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Author: Simon Riget
Contributor: <Anton Sychev> (anton at sychev dot xyz)
index.js (c) 2017 - 2023
index.js (c) 2017 - 2024
Created: 2023-10-28 02:12:56
Desc: File tools lock and unlock
License:
Expand Down
2 changes: 1 addition & 1 deletion dist/cjs/utils/filesValidators.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function identifierNameSimplyTest(name: any): boolean;
export function identifierNameSimplyTest(name: string): boolean;
export function identifierNameTest(name: string): boolean;
export function fileNameWash(name: any, preserve_wildcards?: any): any;
15 changes: 8 additions & 7 deletions dist/cjs/utils/filesValidators.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mjs/constants.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Author: Simon Riget
Contributor: <Anton Sychev> (anton at sychev dot xyz)
index.mjs (c) 2017 - 2023
index.mjs (c) 2017 - 20234
Created: 2023-10-28 02:12:56
Desc: Constants variables
License:
Expand Down
4 changes: 2 additions & 2 deletions dist/mjs/index.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Author: Simon Riget
Contributor: <Anton Sychev> (anton at sychev dot xyz)
index.mjs (c) 2017 - 2023
index.mjs (c) 2017 - 2024
Created: 2023-10-26 02:43:48
Desc: Rocket Store - A very simple and yet powerful file storage.
License:
Expand Down Expand Up @@ -101,7 +101,7 @@ Rocketstore.options = async (options = {}) => {
if (typeof options.lock_files === "boolean")
Rocketstore.lock_files = options.lock_files;
// filecheck
if (typeof options.check_files === "boolean")
if (typeof options.check_files === "number")
Rocketstore.check_files = options.check_files;
};
/**
Expand Down
2 changes: 1 addition & 1 deletion dist/mjs/utils/files.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Author: Simon Riget
Contributor: <Anton Sychev> (anton at sychev dot xyz)
index.mjs (c) 2017 - 2023
index.mjs (c) 2017 - 2024
Created: 2023-10-28 02:12:56
Desc: File tools lock and unlock
License:
Expand Down
2 changes: 1 addition & 1 deletion dist/mjs/utils/filesValidators.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function identifierNameSimplyTest(name: any): boolean;
export function identifierNameSimplyTest(name: string): boolean;
export function identifierNameTest(name: string): boolean;
export function fileNameWash(name: any, preserve_wildcards?: any): any;
15 changes: 8 additions & 7 deletions dist/mjs/utils/filesValidators.mjs

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions examples/index.js → examples/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ const rs = require("rocket-store").default;
const options = {
data_storage_area: "./webapp",
data_format: rs._FORMAT_JSON,
check_files: rs._FILECHECK_LOW,
};

await rs.options(options);

console.log("POST a record:\n", await rs.post("cars", "Mercedes_Benz_GT_R", { owner: "Lisa Simpson" }));
//invalid collection
try {
console.log("POST a invalid record:\n", await rs.post("return``", "Mercedes_Benz_GT_R", { owner: "Lisa Simpson" }));
} catch (e) {
console.log("error:", e.message);
}

console.log("GET a record:\n", await rs.get("cars", ""));
console.log("POST a record:\n", await rs.post("cars", "Mercedes_Benz_GT_R", { owner: "Lisa Simpson" }));

// Post 3 records
await rs.post("cars", "BMW_740li", { owner: "Greg Onslow" }, rs._ADD_AUTO_INC);
Expand Down
33 changes: 33 additions & 0 deletions examples/cjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions examples/cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "rocket-store-example",
"main": "index.js",
"scripts": {
"test": "node index.js"
},
"dependencies": {
"rocket-store": "file:../.."
}
}
8 changes: 8 additions & 0 deletions examples/index.mjs → examples/mjs/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ import * as store from "rocket-store";
const rs = await store.Rocketstore({
data_storage_area: "./webapp",
data_format: store._FORMAT_JSON,
check_files: store._FILECHECK_LOW,
});

(async () => {
//invalid collection
try {
console.log("POST a invalid record:\n", await rs.post("return``", "Mercedes_Benz_GT_R", { owner: "Lisa Simpson" }));
} catch (e) {
console.log("error:", e.message);
}

// Change storage area from default ( <tempdir>/rsdb )
console.log("POST a record:\n", await rs.post("cars", "Mercedes_Benz_GT_R", { owner: "Lisa Simpson" }));
console.log("GET a record:\n", await rs.get("cars", ""));
Expand Down
32 changes: 32 additions & 0 deletions examples/mjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/mjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "rocket-store-example",
"type": "module",
"main": "index.mjs",
"scripts": {
"test": "node index.mjs"
},
"dependencies": {
"rocket-store": "file:../.."
}
}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rocket-store",
"version": "0.10.18",
"version": "0.10.19",
"description": "A simple, super fast and yet powerfull flat file database.",
"main": "./dist/cjs/index.js",
"module": "./dist/mjs/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Author: Simon Riget
Contributor: <Anton Sychev> (anton at sychev dot xyz)
index.js (c) 2017 - 2023
index.js (c) 2017 - 20234
Created: 2023-10-28 02:12:56
Desc: Constants variables
License:
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Author: Simon Riget
Contributor: <Anton Sychev> (anton at sychev dot xyz)
index.js (c) 2017 - 2023
index.js (c) 2017 - 2024
Created: 2023-10-26 02:43:48
Desc: Rocket Store - A very simple and yet powerful file storage.
License:
Expand Down Expand Up @@ -125,7 +125,7 @@ Rocketstore.options = async (options = {}) => {
if (typeof options.lock_files === "boolean") Rocketstore.lock_files = options.lock_files;

// filecheck
if (typeof options.check_files === "boolean") Rocketstore.check_files = options.check_files;
if (typeof options.check_files === "number") Rocketstore.check_files = options.check_files;
};

/**
Expand All @@ -144,6 +144,7 @@ Rocketstore.post = async (collection, key, record, flags) => {
if (Rocketstore.check_files === _FILECHECK_DEFAULT)
if (!identifierNameTest(collection))
throw new Error("Collection name contains illegal characters (For a javascript identifier)");

if (Rocketstore.check_files === _FILECHECK_LOW)
if (!identifierNameSimplyTest(collection))
throw new Error("Collection name contains illegal characters (For a javascript identifier)");
Expand Down
Loading

0 comments on commit b6063e6

Please sign in to comment.