GithubHelp home page GithubHelp logo

burawi / tayr Goto Github PK

View Code? Open in Web Editor NEW
20.0 20.0 2.0 3.65 MB

an easy on-the-fly ORM for NodeJS, inspired by RedBeanPHP

Home Page: http://burawi.github.io/tayr/

License: MIT License

JavaScript 100.00%

tayr's People

Contributors

3imed-jaberi avatar burawi avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

tayr's Issues

Error handling

hi,

I really like redbeanphp, and finding your library made me excited, however before I can use it, I see a few problems.

first one is I don't see any way to handle errors. The most basic example being:

var nest = require('Tayr');
var T = new nest({
	host: 'localhost',
	database: 'databaseName'
});

if there is no MySQL server running on localhost, connection.connect(); will get ECONNREFUSED, however, there is no callback given to it, to get the error and reject the promise.

sequelize for example lets you handle connections errors this way:

sequelize
  .authenticate()
  .then(() => {
    console.log('Connection has been established successfully.');
  })
  .catch(err => {
    console.error('Unable to connect to the database:', err);
  });

maybe we can expose the createDb function instead of executing it automatically, and allow the user to catch connection errors that way ?

var nest = require('Tayr');
var T = new nest({
	host: 'localhost',
	database: 'databaseName'
}); // createDb is not called automatically, so no exception is raised

T.createDb().then(()=>{
// database is ready
}).catch((err)=>{
//err can be ECONNREFUSED
})

another example is on line 497, if (err) throw err; will either crash the node process or keep the promise in pending state indefinitely.

Instead, something like if (err) return reject(err); would be more appropriate. The goal here is to allow catching and handling of errors in user code.

I also think that the onReject method is not very helpful, instead, I would prefer if errors would be handlable using a .catch in user code.

new Date() value creating field of type 'INT(11)' rather than 'BIGINT'

Let me just say, I love this module! That being said, I'm having a hard time tracking down why the code below doesn't create a 'BIGINT' field for 'dateCreated'

let userGroup = new T.tayr('userGroup', {
  dateCreated: new Date()
})

let user = new T.tayr('user', {
  firstName: 'Default',
  lastName: 'User'
})

user.setParent(userGroup, function () {
  console.log('User: ' + user.id + ' belongs to group: ' + userGroup.id)
})

userGroup.store(function () {
    user.store(function () {
      console.log('stored:' + userGroup + ' and: ' + user)
    })
})

Any ideas?

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.