vidigami / backbone-orm Goto Github PK
View Code? Open in Web Editor NEWA polystore ORM for Node.js and the browser
Home Page: http://vidigami.github.io/backbone-orm
License: MIT License
A polystore ORM for Node.js and the browser
Home Page: http://vidigami.github.io/backbone-orm
License: MIT License
I got this error using component.
The problem seems to be that your internal require implementation uses window.require
as a fallback to require its dependencies. Component, however, does not allow "deeper" components to require their dependencies via the top-level require
and instead provides every module with a specialized locally injected require
variable.
A workaround would be to add the dependency to the window object, but that's not really the point of using a module require system, I think :)
A fix would be to grab the originally injected local require and save it for later e.g. as externalRequire
. This could then be used inside your internal require as a fallback.
Ensure join table locations are deterministic
When express parses an id, it leaves it as a string meaning if integers are used on the client for PUT on the server, it cannot find the model by id (req.params.id is a string).
Make the model lookup check for string to integer conversion.
Browserify, AMD, and global should be built and run in a browser automatically
Hello,
it is not quite clear to me how to use backbone-orm and backbone-mongo correctly.
For example, I have a User model, which has a 'hasMany' relationship to 'Address'.
In turn, the address has a 'belongsTo' relationships to 'User'.
Question 1:
When I create instances, how would I go about attaching those to one another?
When I do this
user = new User { ... }
address = new Address { ... }
address.set 'user', user
user.save()
then the user gets saved properly, as does the address, but the user_id of the address is 'null'.
However, when I do address.save()
before saving the user, then I have two identical address objects in my database, but the user still has an address_id of 'null'
Question 2:
How would I set up the relation from the other side?
How do I say in code 'Make it so that these address instances are attached to this user instance'?
I am generally confused, since on the documentation website there are only examples for finding stuff, so I don't even know whether my approach of using model.set(schemeProperty, value)
is correct at all...
Thanks and regards,
Thomas
Implement a pipeline of operations like mongo aggregation framework and pre-pick the unique records
hey, I'm trying to find a solution for an "offline-first" application where the data is stored first in the browser but can be populated from the server. will this work with your backbone-orm suite?
On trying to connect with MySQL running in a docker container, thus using non-default port number, I am observing knex trying to connect with port 3306 on proper IP address.
So I tried to find root cause for this and found backbone-orm's DatabaseURL to rely on NodeJS parsing URL resulting in host
providing hostname incl. port number while hostname
isn't including port number. backbone-sql is then using hostname
to provide connection info for knex which is thus not including port number.
At first glance this issue seems to be more related to backbone-sql, however the code in DatabaseURL
of backbone-orm looks rather strange. This is related to processing URL providing multiple hosts differently when compared with behaviour of NodeJS's URL parsing library as of 4.3.x.:
@hosts = []
for database in databases
host = database.split(':')
@hosts.push if host.length is 1 then {host: host[0], hostname: host[0]} else {host: host[0], hostname: "#{host[0]}:#{host[1]}", port: host[1]}
On providing multiple server addresses separated by comma this code is used and thus the resulting property per host including custom port number is hostname
(different from NodeJS URL parsing, but would be matching expectation of backbone-sql) while on providing single host name only the result of NodeJS's URL parsing is taken as-is, so host
is including port number rather than hostname
. And basically I agree with NodeJS behaviour for the name of host doesn't include port numbers.
This is a minor issue and I will fix it.
Backbone = require 'backbone'
class A extends Backbone.Model
urlRoot: '/api/as'
schema:
b: -> ['belongsTo', B, manual_fetch: true]
sync: require('backbone-http').sync(A)
class B extends Backbone.Model
urlRoot: '/api/bs'
schema:
a: -> ['hasOne', A, manual_fetch: true]
sync: require('backbone-http').sync(B)
a = new A({b: {id: 1}})
a.get('b_id') # => 1
a.pick('b_id') # => {} SHOULD BE {b_id: 1}
Hello,
how would I work with relations between entities? E.g. I want all items that can be purchased in a certain store. How would I do that using backbone-orm?
thanks in advance
Query caching is disabled by default and suffers from coherency issues when multiple servers are trying to share a QueryCache.
Look into it.skip and @embed tests
I am getting this error when calling save on a model I have just changed.
Failed to create model. Error: MongoError: insertDocument :: caused by :: 11000 E11000 duplicate key error index: integration-test.users.$id dup key: { : ObjectId('5476438c9b93233f6a6414f0') }
Code:
waterfall [
(next) ->
User.findOne { email }, (err, user) ->
next err, user
(user, next) ->
user.set { address }
user.save (err, user) ->
next err, user
], callback
I will provide more information or code if needed.
Isn't it supposed to work this way, and Backbone sync implementation should take care of wether it should be an update?
I also tried with Backbone's { patch: true }
, but then the call to save()
does not return at all.
Make sure API for model conventions is easy to use
In a number of places, _.isNull
is used where it seems like the existential operator (?
) would be a better fit (not foo?
is the same as _.isNull(foo) and _.isUndefined(foo)
)
Currently if you use a BackboneORM sync and you want to overide a method, super is broken
Having models in different files and referencing each other via require
leads to TypeError: Cannot read property 'schema' of undefined
errors in node
the following line throws an error:
https://github.com/vidigami/backbone-orm/blob/master/src/relations/many.coffee#L120
targetProto = this.model.prototype
^
backbone.Collection#set
backbone.Colleciton#add
backbone-orm.Many#add
One#_bindBacklinks.setBacklink(<Anonymous Function>)
One#_bindBacklinks
One#initializeModel
overrides.initialize
Backbone.Model
extend.child
new MyApp.MyModel
(This is a handwritten stack since the original files & line numbers are pretty arbitrary.)
I don't know why this happens, so I thought you might know more.
Cursor can select fields from json
Cursor can select values from json
$unique uses postgres specific functions for some functionality.
distinct
query is used. This will work with mysql, etc.$unique uses the mongodb aggregation framework. There are limitations involved, so results are a bit different than with postgres.
Cursors should have a iteration mechanism.
BackboneHTTP can send too many requests to the server during create and patch. It should be able to send a graph of JSON to create and return a graph of models.
Update tests to use this to try to speed up the setup step
Is it possible to use a PHP MySql backend?
This would be to allow use of SQL's DISTINCT
and mongo's collection.distinct()
Syntax would either be
{$distinct: ['column_name']}
or
{column_name: {$distinct: true}}
I'd like to be able to change the type of the primary key (changing the field name would be nice to have, too), can I simply override it in my schema definition?
In order to avoid race conditions, findOrCreate should use available upsert mechanisms when available (db.collection.update(<query>,<update>,{upsert: true})
in mongodb, varied support in sql backends)
Hey,
I'd love to have component support for this!
Hi again,
say I have a model that extends another model, like StaffUser and User for example.
Now when I set it up like the examples suggest, but also have StaffUser extends User
, then, besides still having the problem, that the foreign keys for the relationships do not get set properly (#48), my 'Address' instance (when assigning a 'StaffUser' instance to its 'user' property) now has two fields, user_id
and staff_user_id
(both 'null' as of issue mentioned before).
I realise this is a complex issue, and coming from an object oriented background I might be expecting too much.
However your software looks very promising, and even without this feature it would save a lot of boilerplate code.
Thanks for your help!
Thomas
Hi, it looks like a promising project!
I know its great having both the # Node style
project.save (err, project) ->
return console.log 'Oh no an error' if err
console.log "We're saved!"
and # Backbone style
project.save {
success: (project) -> console.log "We're saved!"
error: (project, err) -> console.log 'Oh no an error'
}
callback styles.
But how about returning a when.js/Promises A+ promise, when save()
is called without a param ? It would greatly appeal to all promising developers out there!
Hi,
i play around with some models and sqlite adapter that is working well and fits my needs so far.
What i can't figure out is a good way to crate a collection of models with backbone-orm. Unfortunately i can not find an example, or webresource. (For a short moment I wonder if i am the only one who think that a Table, or resultset is a collection of modells).
How do you build up collections of models, that relates to backbone-orm?
How can i become a collection back of a result by filtering a parameter?
Thanks a lot,
ps
Use different parameter sets
Use uRequire to build, with support for AMD, UMD, nodejs and moduless environments (i.e <script>
).
Precise require
ments will follow.
can i use backbone-orm with websql ?
if yes , how can i use it ?
Hi, I am attempting to get started with backbone-orm. When I run the following bit of code:
var Backbone = require("backbone");
var Project = Backbone.Model.extend({
urlRoot : "xxx"
});
Project.prototype.sync = require("backbone-orm").sync(Project);
I get this error:
~\Development\backbone-fs> node .\bug.js
C:\Users\pshangov\Development\backbone-fs\node_modules\backbone-orm\lib\extensions\model_stream.js:5
unction ctor() { this.constructor = child; } ctor.prototype = parent.prototype
^
TypeError: Cannot read property 'prototype' of undefined
at __extends (C:\Users\pshangov\Development\backbone-fs\node_modules\backbone-orm\lib\extensions\model_stream.js:5:199)
at C:\Users\pshangov\Development\backbone-fs\node_modules\backbone-orm\lib\extensions\model_stream.js:19:5
at Object.<anonymous> (C:\Users\pshangov\Development\backbone-fs\node_modules\backbone-orm\lib\extensions\model_stream.js:51:5)
at Object.<anonymous> (C:\Users\pshangov\Development\backbone-fs\node_modules\backbone-orm\lib\extensions\model_stream.js:53:4)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
OS: Windows 7 64-bit
node version 0.8.21
backbone-orm version 0.5.1
The same happens on latest version from git (eb085e5)
There is no error if I comment out the "Project.prototype.sync = ..." line.
Cheers,
Peter
The tests should pass for:
I'm using Backbone in back and front end.
I configured Backbone-ORM + Backbone-HTTP in my "client" web app and used Backbone-ORM + Backbone-Mongo + Backbone-REST in my REST API.
It worked fine until I tested some queries using relationship keys from my client against the REST API.
Product.find({
category_id: '5785228fc2ad8a23481dbb75'
}, function (err, products) {
$("body").html(JSON.stringify(products));
});
The request that is made:
http://localhost:8080/products?category_id=%225785228fc2ad8a23481dbb75%22
That means that the category_id here is interpreted as number represented in string, and therefore must be "quoted".
But I don't think that is the expected result. Even more when the restify server, with the Backbone-REST on top of it, doesn't interpret it right and the GET returns []
, even though the request without the quotes return it right.
Add conventions configuration
Add how to write and test a custom sync
Explain how to implement a REST controller in a different language
Explain how database tools work for Mongo and SQL
The test commands for BackboneORM and BackboneHTTP should be identical and robust.
The commands scenarios with task names should be agreed and listed in README.md
Hi again!
I wanted to quickly ask, if there is a recommended way to set both 'createdAt' timestamp and 'updatedAt' timestamp. The 'created' one could be defined in the model as having a default value of 'new Date()', but how about the 'updatedAt' one?
I was just evaluating waterline, and came across this feature, which I found pretty nice:
https://github.com/balderdashy/waterline-docs/blob/master/models.md#autocreatedat
Related question:
Are there any hooks, like 'beforeSave' or similar, that could be used for that purpose?
Excuse me if that should be covered by Backbone knowledge I do not yet have ;)
Again, thanks for your help, it is very much appreciated!
Thomas
So, I've got a model Apple
:
var Apple = Backbone.Model.extend({
schema: {
origin: ['belongsTo', Farm]
}
})
And a Juice
model:
var Juice= Backbone.Model.extend({
schema: {
origin: ['belongsTo', Farm]
}
})
Question: Can I simply do the following to overtake the apple's origin?
var juice = new Juice({
origin: juicyApple.get('origin')
})
Juice.save(...)
It should have a quick flag to only test one variant
It should be implemented for BackboneORM and BackboneHTTP
Currently tests are written that require stream and jQuery
Is this library compatible with socket.io-based sync solutions like backbone.io or backbone.iobind? In other words, if you dropped on of them into the sync hook, would it break backbone-orm? I'm guessing it would since the sync hook seems to be the only way the Model becomes "aware" that it's an ORM model. In any case, it would be nice if it were possible to use this in a real-time socket.io setup. It would be extra special if there was firebase option also.
http://backbonejs.org/#Model-save
Before the original backbone.Model::save call is made, the attributes are explicitly set in the save override, but with {wait: true}
, that shouldn't happen.
On the line here, it should be Utils.inspect
, not util.inspect
. https://github.com/vidigami/backbone-orm/blob/master/src/relations/many.coffee#L50
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.