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

Can't store a function #448

Closed
deminearchiver opened this issue Aug 1, 2022 · 4 comments · Fixed by #449
Closed

Can't store a function #448

deminearchiver opened this issue Aug 1, 2022 · 4 comments · Fixed by #449

Comments

@deminearchiver
Copy link

deminearchiver commented Aug 1, 2022

Whenever I try to push a function (or an object with a function), it gets removed as soon as the database restarts (reloads), so it only exists at runtime:

db.push("/func", () => console.log("It is a function!"));

console.log(db.getData("/func")) //Outputs: [Function (anonymous)]

//Remove the push call, restart the app
console.log(db.getData("/func")) //DataError: Can't find dataPath: /func. Stopped at func

Will there ever be added support for storing functions?

@Belphemur
Copy link
Owner

Hello,
Actually, I should check we're trying to store a function and throw an exception.
I won't add support for this, as this is a rabbit hole of complexity that in most use case won't even work properly.

Nice stack overflow on how to implement it, but with a lot of caveats:
https://stackoverflow.com/questions/7395686/how-can-i-serialize-a-function-in-javascript

@Belphemur
Copy link
Owner

With the new version you'll be able to write your own adapter if you want to support function serialization.

github-actions bot pushed a commit that referenced this issue Aug 1, 2022
# [2.0.0](v1.6.0...v2.0.0) (2022-08-01)

### Bug Fixes

* **Array:** Fix array not properly async ([26355b0](26355b0))
* **HumanReadable:** Fix missing humanreadable ([13e51d9](13e51d9))
* **JsonAdapter:** Don't override the data property ([817c581](817c581))

### Features

* **Adapter:** Add concept of adapter to read and write data ([fcea4bb](fcea4bb))
* **Adapter:** Let the user decide what adapter to use if they want to tweak the inner working ([c8f264b](c8f264b)), closes [#448](#448)
* **Async:** All the method are now async/await ([ab63e82](ab63e82)), closes [#171](#171)
* **Async:** Make the whole library async ([764cdf4](764cdf4)), closes [#444](#444)
* **AtomicFileAdapter:** Add support for fsync ([4a51239](4a51239))
* **Configuration:** Force giving a config object to the constructor ([002a72a](002a72a))

### BREAKING CHANGES

* **Async:** Every method of the library is now async and returns a promise.
* **Configuration:** We now need to receive the JsonDBConfig object in the constructor
@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2022

🎉 This issue has been resolved in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Belphemur added a commit that referenced this issue Sep 9, 2022
Belphemur pushed a commit that referenced this issue Sep 9, 2022
# [2.0.0](v1.6.0...v2.0.0) (2022-08-01)

### Bug Fixes

* **Array:** Fix array not properly async ([26355b0](26355b0))
* **HumanReadable:** Fix missing humanreadable ([13e51d9](13e51d9))
* **JsonAdapter:** Don't override the data property ([817c581](817c581))

### Features

* **Adapter:** Add concept of adapter to read and write data ([fcea4bb](fcea4bb))
* **Adapter:** Let the user decide what adapter to use if they want to tweak the inner working ([c8f264b](c8f264b)), closes [#448](#448)
* **Async:** All the method are now async/await ([ab63e82](ab63e82)), closes [#171](#171)
* **Async:** Make the whole library async ([764cdf4](764cdf4)), closes [#444](#444)
* **AtomicFileAdapter:** Add support for fsync ([4a51239](4a51239))
* **Configuration:** Force giving a config object to the constructor ([002a72a](002a72a))

### BREAKING CHANGES

* **Async:** Every method of the library is now async and returns a promise.
* **Configuration:** We now need to receive the JsonDBConfig object in the constructor
github-actions bot pushed a commit that referenced this issue Sep 9, 2022
# [3.0.0](v2.1.1...v3.0.0) (2022-09-09)

### Bug Fixes

* **Array:** Add support for dash in array name ([b001403](b001403)), closes [#98](#98)
* **Array:** Fix array not properly async ([7bfd98d](7bfd98d))
* **ArrayInfo:** Returns type of isValid ([d206098](d206098))
* **Array:** Support dot and number in name ([eb89a42](eb89a42)), closes [#95](#95)
* **Concurrency:** Fix issue with concurrent push from different sources ([daae2bb](daae2bb)), closes [#484](#484)
* **Config:** put proper default for ConfigWithAdapter ([dbb3b7b](dbb3b7b))
* **Convention:** Fixed quotes ([7126cad](7126cad))
* **Docs:** Be sure the doc contains Config ([c453c5d](c453c5d))
* **getIndex:** Improve documentation ([17ba435](17ba435))
* **HumanReadable:** Fix missing humanreadable ([4a2d198](4a2d198))
* **JsonAdapter:** Don't override the data property ([43898d5](43898d5))
* **Packaging:** Add type to package. ([983ea99](983ea99)), closes [#58](#58) [#57](#57)
* **README:** Update documentation ([d66d712](d66d712))
* **README:** Update documentation ([ba42a83](ba42a83)), closes [#90](#90) [#85](#85)
* **Separator:** Fix still using the slash as separator. ([c4c18b8](c4c18b8))

### Features

* **Adapter:** Add concept of adapter to read and write data ([9a31abc](9a31abc))
* **Adapter:** Let the user decide what adapter to use if they want to tweak the inner working ([975a653](975a653)), closes [#448](#448)
* add some array utils ([c85618e](c85618e))
* **Array:** Add support for nested array ([57c049f](57c049f)), closes [#422](#422) [#417](#417)
* **Async:** All the method are now async/await ([a6a4a8d](a6a4a8d)), closes [#171](#171)
* **Async:** Make the whole library async ([b99d784](b99d784)), closes [#444](#444)
* **AtomicFileAdapter:** Add support for fsync ([e4760cb](e4760cb))
* **Config:** Add Config file to setup the Database ([3915aee](3915aee))
* **Configuration:** Force giving a config object to the constructor ([8e415e6](8e415e6))
* **Date:** Add support for serializing and deserializing date type ([e62e792](e62e792)), closes [#362](#362)
* **Exists:** Add exits method ([35152a2](35152a2)), closes [#19](#19)
* **filename:** Support non json file extensions ([6be9a1d](6be9a1d))
* **Filter:** Add filtering feature ([0f7d276](0f7d276))
* **find:** Add find feature ([bd7ab4c](bd7ab4c)), closes [#17](#17)
* **FSYNC:** Optional fsync when saving the database ([8ae82ab](8ae82ab)), closes [#372](#372)
* **getIndex:** Support Numerical id ([d2e88ea](d2e88ea))
* **GetIndexValue:** Get index of a value in an array ([35d1807](35d1807)), closes [#191](#191)
* **Packaging:** Use es6 module packaging ([4487c4b](4487c4b))
* **typing:** Add basic typing to the lib for TS ([db8ab77](db8ab77))

### Performance Improvements

* **Concurrency:** Be sure that only one read or one write can be done at the same time ([1cf0038](1cf0038))
* **Config:** Easier way to import the configuration of JsonDB ([e371b71](e371b71))
* **Errors:** Export errors for easier error management in other projects ([60c90f8](60c90f8)), closes [#479](#479)

### BREAKING CHANGES

* **Async:** Every method of the library is now async and returns a promise.
* **Configuration:** We now need to receive the JsonDBConfig object in the constructor
* **Packaging:** The default export has been removed. You need to do a deconstruction import to load the library now.

import JsonDB from 'node-json-db'
becomes
import {JsonDB} from 'node-json-db'
@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2022

🎉 This issue has been resolved in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Sep 9, 2022
# [1.0.0](v0.7.3...v1.0.0) (2022-09-09)

### Bug Fixes

* **Array:** Add support for dash in array name ([b001403](b001403)), closes [#98](#98)
* **Array:** Fix array not properly async ([7bfd98d](7bfd98d))
* **ArrayInfo:** Returns type of isValid ([d206098](d206098))
* **Array:** Support dot and number in name ([eb89a42](eb89a42)), closes [#95](#95)
* **Concurrency:** Fix issue with concurrent push from different sources ([daae2bb](daae2bb)), closes [#484](#484)
* **Config:** put proper default for ConfigWithAdapter ([dbb3b7b](dbb3b7b))
* **Convention:** Fixed quotes ([7126cad](7126cad))
* **Docs:** Be sure the doc contains Config ([c453c5d](c453c5d))
* **getIndex:** Improve documentation ([17ba435](17ba435))
* **HumanReadable:** Fix missing humanreadable ([4a2d198](4a2d198))
* **JsonAdapter:** Don't override the data property ([43898d5](43898d5))
* **Packaging:** Add type to package. ([983ea99](983ea99)), closes [#58](#58) [#57](#57)
* **README:** Update documentation ([d66d712](d66d712))
* **README:** Update documentation ([ba42a83](ba42a83)), closes [#90](#90) [#85](#85)
* **Separator:** Fix still using the slash as separator. ([c4c18b8](c4c18b8))

### Features

* **Adapter:** Add concept of adapter to read and write data ([9a31abc](9a31abc))
* **Adapter:** Let the user decide what adapter to use if they want to tweak the inner working ([975a653](975a653)), closes [#448](#448)
* add some array utils ([c85618e](c85618e))
* **Array:** Add support for nested array ([57c049f](57c049f)), closes [#422](#422) [#417](#417)
* **Async:** All the method are now async/await ([a6a4a8d](a6a4a8d)), closes [#171](#171)
* **Async:** Make the whole library async ([b99d784](b99d784)), closes [#444](#444)
* **AtomicFileAdapter:** Add support for fsync ([e4760cb](e4760cb))
* **Config:** Add Config file to setup the Database ([3915aee](3915aee))
* **Configuration:** Force giving a config object to the constructor ([8e415e6](8e415e6))
* **Date:** Add support for serializing and deserializing date type ([e62e792](e62e792)), closes [#362](#362)
* **Exists:** Add exits method ([35152a2](35152a2)), closes [#19](#19)
* **filename:** Support non json file extensions ([6be9a1d](6be9a1d))
* **Filter:** Add filtering feature ([0f7d276](0f7d276))
* **find:** Add find feature ([bd7ab4c](bd7ab4c)), closes [#17](#17)
* **FSYNC:** Optional fsync when saving the database ([8ae82ab](8ae82ab)), closes [#372](#372)
* **getIndex:** Support Numerical id ([d2e88ea](d2e88ea))
* **GetIndexValue:** Get index of a value in an array ([35d1807](35d1807)), closes [#191](#191)
* **Packaging:** Use es6 module packaging ([4487c4b](4487c4b))
* **typing:** Add basic typing to the lib for TS ([db8ab77](db8ab77))

### Performance Improvements

* **Concurrency:** Be sure that only one read or one write can be done at the same time ([1cf0038](1cf0038))
* **Config:** Easier way to import the configuration of JsonDB ([e371b71](e371b71))
* **Errors:** Export errors for easier error management in other projects ([60c90f8](60c90f8)), closes [#479](#479)

### BREAKING CHANGES

* **Async:** Every method of the library is now async and returns a promise.
* **Configuration:** We now need to receive the JsonDBConfig object in the constructor
* **Packaging:** The default export has been removed. You need to do a deconstruction import to load the library now.

import JsonDB from 'node-json-db'
becomes
import {JsonDB} from 'node-json-db'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants