Giter VIP home page Giter VIP logo

Comments (6)

bigfarofa avatar bigfarofa commented on August 25, 2024

I forgot to check the method fromInstance. Probably it will work.

from nedb-promise.

jrop avatar jrop commented on August 25, 2024

@DREZZ3R fromInstance will probably work. However, at the top of index.js, I have the line require('nedb'), so this will probably require a bit of refactoring to fully support the browser. I can probably accomplish this with the following steps:

  1. Split fromInstance into its own file
  2. Create browser.js that requires nedb/browser-version/out/nedb.min.js and then uses fromInstance to promisify that
  3. Create a WebPack config to bundle all of this together

It would also be good to add some tests that run in the browser, using Karma, or something like that. Perhaps I'll take the opportunity to also convert this repo to TypeScript

from nedb-promise.

bigfarofa avatar bigfarofa commented on August 25, 2024

@jrop I've tried using the browser version, but it just does not work. I tested with this code:

import Nedb from 'nedb/browser-version/out/nedb.min.js';
import nedbPromify from 'nedb-promise';
let db = nedbPromify.fromInstance(new Nedb('images', {autoload: true}))
db.findOne({})
.then(("findOne RES", res) => console.log(res))
.catch(("findOne ERR", err) => console.log(err))

This does not give any error, it just stops. If I use this in an async function everything after the query, is not executed.

from nedb-promise.

jrop avatar jrop commented on August 25, 2024

@DREZZ3R That does not seem to be valid syntax:

.then(("findOne RES", res) => console.log(res))
// Should be?: .then((res) => console.log("findOne RES", res))
.catch(("findOne ERR", err) => console.log(err))
// Should be?: .catch((err) => console.log("findOne ERR", err))

It seems that the only parsers that accept that syntax are Flow and TypeScript, and even then, they see that as a parenthesized comma-expression, with a second argument of console.log(...). I bet if you changed to the syntax proposed above the callbacks might get executed

from nedb-promise.

bigfarofa avatar bigfarofa commented on August 25, 2024

@jrop I figured it out. Yes, the syntax I wrote here is wrong, but in the app's source code was right and didn't work.
The problem was how I created the Nedb instance.

How it was:

let db = nedbPromify.fromInstance(new Nedb('images', {autoload: true}))

How it should've been:

let db = nedbPromify.fromInstance(new Nedb({filename: "images", autoload: true}))

I thought the first argument was the DB name and then options as second. Nedb only accepts one argument either a string or a object with options. I feel stupid, thank you for your patience.

from nedb-promise.

jrop avatar jrop commented on August 25, 2024

@DREZZ3R Awesome, glad it's solved! I do eventually want to convert this to TypeScript so that errors such as this are easier to spot; I just have to find time lol

from nedb-promise.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.