Coder Social home page Coder Social logo

cozy-db's Introduction

Cozy ORM

Replacement of jugglingdb for cozy application.

Read the doc

Contribution

You can contribute to cozydb in many ways:

  • Pick up an issue and solve it.
  • Write new tests.

Before submitting a pull request, make sure you have build & linted your code with

npm run prepublish

Tests

Build Status

Run tests with following commmand

npm test

LICENSE

MIT

What is Cozy?

Cozy Logo

Cozy is a platform that brings all your web services in the same private space. With it, your web apps and your devices can share data easily, providing you with a new experience. You can install Cozy on your own hardware where no one profiles you.

Community

You can reach the Cozy Community by:

  • Chatting with us on IRC #cozycloud on irc.freenode.net
  • Posting on our Forum
  • Posting issues on the Github repos
  • Mentioning us on Twitter

cozy-db's People

Contributors

aenario avatar bnjbvr avatar clochix avatar jsilvestre avatar ljinod avatar nono avatar paultranvan avatar poupotte avatar runvnc avatar zehiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cozy-db's Issues

Bad parameter in error message

Hi,

This error message does not output the expected sentence, I think.

At least, in Konnectors, when using the dev tools, I get a lot of

warn - Cozy DB | Warning : cast ignored property 'fetch' on 'ClassFromGetModel'

which is ok, except that I would have expected an actual model name rather than "ClassFromGetModel".

cc @ZeHiro

Remove useless `id` key attribute

Historically, when JugglingDB was in use, we must keep an id key attribute. Now, this attribute is just a duplicate of the native _id couchdb attribute.

As long as the id attribute isn't really useful, I suggest we deprecate it slowly by using the _id attribute in models.

Repositorty ownership

Hi @aenario,

This new ODM is really cool. But it doesn't appear in the Cozy repository list. Could you give the repository ownership to the Cozy organisation?

Different behavior in Find

STR

  • use the find method of any Model with an invalid id, so as to trigger the "not found" behavior:
    1. once with the pouchdb backed model
    2. once with the cozy backed model

Expected

No difference in behavior.

Observed

  • pouchdb calls the callback with a non-null error
  • cozydb silently calls the callback with (null, null)

Unexpected end of input

When trying to create an object in the DataSystem with [email protected] for a side project, I get this error in the DataSystem logs:

SyntaxError: Unexpected end of input
    at Object.parse (native)
    at parse (/usr/local/cozy/apps/data-system/node_modules/americano/node_modules/body-parser/index.js:65:17)
    at /usr/local/cozy/apps/data-system/node_modules/americano/node_modules/body-parser/index.js:180:18
    at IncomingMessage.onEnd (/usr/local/cozy/apps/data-system/node_modules/americano/node_modules/body-parser/node_modules/raw-body/index.js:117:7)
    at IncomingMessage.g (events.js:180:16)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

I just switched to version 0.0.16 for now and it's working fine so far.

.api functions always use the DS, never pouchdb

THis is due to the order of require and the fact that we only know to use pouchdb after the configure, so CozyUser & CozyInstance already extends the CozyBackedModel. Easiest way would probably to override them both in the if (pouchdb) as we do for CozyModel.

No search in standalone

The search functionality does not work in standalone mode.

To be considered when selecting new indexer method

Too deeply linked with americano

Trying to use cozydb without americano is akward.

One needs to

  1. create a file /some/path/server/models/requests.(js|coffee)
  2. manually cozydb.configure '/some/path/'

The latest version doesn't seem to like passwords

Hi,

To keep it short, I have this create call. The console.log sure isn't really secure, but I was working on an issue where I couldn't retrieve a supposed saved password, so I wanted to know what cozydb saved.
I have this output:

{ username: 'baboli18',
  password: '***********',
  tgc: 
   { key: 'CASTGC',
     value: 'TGT-598-rkm2FKaZBHIDLYFAORuWljLn1b2h26CVyW5ka6qlTeI3tfjeZj-cas',
     domain: 'web.isen-bretagne.fr',
     path: '/cas',
     secure: true,
     hostOnly: true,
     creation: '2015-08-24T16:29:18.975Z',
     lastAccessed: '2015-08-24T16:29:18.977Z' },
  jsessionid: 
   { key: 'JSESSIONID',
     value: 'F62053FD6C6FA9BAD8B96B6564919888',
     domain: 'web.isen-bretagne.fr',
     path: '/',
     secure: true,
     hostOnly: true,
     creation: '2015-08-24T16:29:17.800Z',
     lastAccessed: '2015-08-24T16:29:18.977Z' },
  _id: 'b359c1912482968bb7e0d84c76012f35',
  _attachments: undefined,
  _rev: undefined,
  id: 'b359c1912482968bb7e0d84c76012f35',
  docType: 'caslogin',
  binaries: undefined }

The censored "password" field is my password, which match with the valid value.

After this, I go look in the DataBrowser, the password field isn't filled. The next step in the app include a check with the said password, which seems to be undefined.
Here's the log from my DataSystem.

If it can help, I'm running the app on an ISEN Cozy, and I'm (supposedly) using the latest version of cozydb (set to latest in the package.json).

Sanitize tags

Cozydb.api.getCozyTags should prevent strange tags situation from the DS

tags = tags.filter (value) -> Boolean(value)

instance.save changed semantics

So, by mistake I changed model.save to not create the model if it doesnt exist.
When converting applications to cozydb, I removed all .save and replaced them by .updateAttributes

It's better, because save will erase unknown fields :
Let's say app 1 has a Book model, with schema {isbn, title}
And app 2 has a Book model, with schema {isbn, title, summary}
And we update the model with a .save, the summary will be lost

I think we should remove the .save method.

"cozydb failed to load" on Archlinux

Hey there,

Whenever I try to launch the americano server of my Cozy app, I get this error:

$ coffee server.coffee
[2015-06-19 10:26:19:427] info - americano | add plugin: cozydb
template - all request creation...
[2015-06-19 10:26:19:494] error - americano | cozydb failed to load.
[Error: "name" and "value" are required for setHeader().]

The rest (routes and development configuration) loads and the server starts.

Using Archlinux (all packages up to date). I don't think it comes from my app since I have the same issue with the templates.

updateAttributes doesn't return the updated doc

When doing a merge, the data system only returns success: true, not the updated document. So we don't get the updated document in the callback of updateAttributes.
I don't know what's the expected behavior, so I'm not providing a patch.

documentation link broken

Hey,

I found this link in the README.md : Read [the doc](http://aenario.github.io/cozydb/doc/DOCINDEX.md.html)
It's broken because the repo was moved.

I didn't fix this in a PR because I didn't found the right link.

Bye

Only String and Number can be defined in getModel() schema

For the moment, when defining a cozy-db database like this:

cozydb.getModel('name', { 'id' : Number, 'label' : String, 'data' : Array });

The result will be for data to be encapsulated in several Arrays when an entry is added to the database with cozydb.create(doc, function(err, docs) {}), where doc is like:

{ 'id' : 1234, 'label' : 'somedata, 'data' : [ {data1}, {data2} ] }

This exit of create function will get doc.data to be like:

'data' : [ [ [ {data1}, {data2} ] ] ]

A workaround is to define data as follow in order to tell cozy-db to let data be as it is:
'data' : cozydb.NoSchema

It would be useful to be able to define a cozydb schema with different types, such as Array, Object, Boolean.

Weird stacktrace in File application

Here is the stacktrace when I run the File application in development mode:

Warning : cast ignored property 'tags' { _id: '5265c17aab710ce182973ddfff4dbdc1',
  fn: 'Benjamin André',
  datapoints: [ { name: 'email', type: 'main', value: '[email protected]' } ],
  note: '',
  tags: [ 'cozy' ],
  docType: 'Contact',
  id: '5265c17aab710ce182973ddfff4dbdc1',
  _attachments: 
   { picture: 
      { content_type: 'application/octet-stream',
        revpos: 4,
        digest: 'md5-GEIFuzq7O0e90cs/6JchrQ==',
        length: 2015,
        stub: true } } } Error
  at exports.castObject.castObject (/home/frankrousseau/mycloud/products/cozy-files/node_modules/cozydb/lib/utils/type_checking.js:119:78)
  at Function.Model.cast (/home/frankrousseau/mycloud/products/cozy-files/node_modules/cozydb/lib/model.js:248:14)
  at Function.module.exports.CozyBackedModel.cast (/home/frankrousseau/mycloud/products/cozy-files/node_modules/cozydb/lib/cozymodel.js:309:57)
  at ClassFromGetModel.Model (/home/frankrousseau/mycloud/products/cozy-files/node_modules/cozydb/lib/model.js:263:24)
  at ClassFromGetModel.CozyBackedModel (/home/frankrousseau/mycloud/products/cozy-files/node_modules/cozydb/lib/cozymodel.js:286:52)
  at new ClassFromGetModel (/home/frankrousseau/mycloud/products/cozy-files/node_modules/cozydb/lib/index.js:48:56)
  at /home/frankrousseau/mycloud/products/cozy-files/node_modules/cozydb/lib/model.js:201:20
  at Array.map (native)
  at /home/frankrousseau/mycloud/products/cozy-files/node_modules/cozydb/lib/model.js:200:41
  at /home/frankrousseau/mycloud/products/cozy-files/node_modules/cozydb/lib/cozymodel.js:254:18
  at parseBody (/home/frankrousseau/mycloud/products/cozy-files/node_modules/cozydb/node_modules/request-json-light/main.js:74:10)
  at IncomingMessage.<anonymous> (/home/frankrousseau/mycloud/products/cozy-files/node_modules/cozydb/node_modules/request-json-light/main.js:99:14)
  at IncomingMessage.EventEmitter.emit (events.js:117:20)
  at _stream_readable.js:920:16
  at process._tickCallback (node.js:415:13)

Apply MyModel.fullTextIndexes system to map-reduce views

I think this way is easier to explain ("You put a model in server/models") than the previous one ("You need to add an entry in server/models/requests which points to a file in the same directory").

I also think we should allow mapreduce views definition in the same way for cozydb v1.0, something like :

class MyModel extends CozyModel
     @docType: 'foo'
     @schema: 
           "bar": String
     @fullTextIndexes: 
           "bar": nGramLength: 1, stemming: true, weight: 5, fieldedSearch: true
     @mapReduceViews:
          "all": cozydb.defaultRequests.all
          "complex": 
               map: (doc) -> emit doc.a / doc.b
               reduce: "_stat"

Consider not finding something as an error ?

Current behaviour, inspired by jugglingdb is to callback(null, null) if the developper try to Model.find "wrong-id".

Source :

find: (id, callback) ->

This leads to 3-ways check in most apps :

Model.find "wrong-id" (err, model) ->
   if err
       next err
   else unless model?
       err = new Error('not found')
       err.status = 404
       next err
    else
       doStuff()

I think it would be more clear to always return either an error or a model.

Fix documentation on save method

I lost hours trying to figure just how to save a document. Documentation says save will create or update the object, but I get not_found: missing errors in the logs when I try to use it to create a new object.
Also documentation says that save should return the updated object. That's not true.

Use printit for logging

Logs for request creation are displayed via a simple console.log instead of using printit.

Explicit error if the DS is down

Now :

2015-03-24 15:04:25:289] info - americano-cozy | instance - all request creation...
[2015-03-24 15:04:25:298] error - americano-cozy | failed Error: connect ECONNREFUSED
[2015-03-24 15:04:25:299] error - americano-cozy | A request creation failed, abandon.
{ [Error: connect ECONNREFUSED]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect' }

Should be

Your Data System appears to be down from http://localhost:9101/

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.