You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Arek W edited this page May 3, 2016
·
10 revisions
After [connecting](Connecting to Database), you can use the connection object (db) to define your models. You need to specify the name of the model, a specification of the properties and options (optional). Here's a small example:
The model is called person (which is usually the name of the table in the database), it has 3 properties (name and surname as text and age as number). A default id: { type: 'serial', key: true } property is added if you don't specify any keys yourself.
In this example there is a model method called fullName. Here's an example of the usage of this model:
Person.get(73,function(err,person){if(err)throwerr;console.log('Hi, my name is '+person.fullName());});
This would get person with id=73 and print it's name and surname. There are other types of [properties available](Model Properties).