node.js - Mongoose: Schema vs Model? -


when looking @ tutorials there delineation between schema , model, particularly when dealing mongoose/mongodb. makes porting on postgresql confusing, 'models' don't seem exist under system. difference 2 approaches?

for example, postgres/sql orm equivalent of line?

(mongoose , express.js):

var userschema = schema.define('local', {     username:       string,     password:       string, });  module.exports = mongoose.model('user', userschema); 

in mongoose, schema represents structure of particular document, either or portion of document. it's way express expected properties , values constraints , indexes. model defines programming interface interacting database (read, insert, update, etc). schema answers "what data in collection like?" , model provides functionality "are there records matching query?" or "add new document collection".

in straight rdbms, schema implemented ddl statements (create table, alter table, etc), whereas there's no direct concept of model, sql statements can highly flexible queries (select statements) basic insert, update, delete operations.

another way think of nature of sql allows define "model" each query selecting particular fields joining records related tables together.

in other orm systems ruby on rails, schema defined via activerecord mechanisms , model methods model subclass adds define additional business logic.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -