concept number in category sails

appears as: number, number, numbers
Sails.js in Action

This is an excerpt from Manning's book Sails.js in Action.

Table 1.3. Common model methods

Method

Description

.create() Creates a new record in the database
.find() Finds and returns all records that match a certain criteria
.findOne() Attempts to find a particular record in your database that matches the given criteria
.update() Updates existing records in the database that match the specified criteria
.destroy() Destroys records in your database that match the given criteria
.count() Returns the number of records in your database that meet the given search criteria
Example 3.2. Adding markup to the homepage
...
  <body>
    <div class="container-fluid">
      <!-- Creates the navbar -->
      <nav class="navbar navbar-default navbar-inverse">
        <!-- This creates the mechanism for collapse button -->
        <button type="button" class="navbar-toggle" data-toggle="collapse"
         data-target=".navbar-collapse">
        <!-- This controls the number of lines in the image when the nav
         collapse -->
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        </button>
        <!-- This is the brandon the left-hand side. -->
        <a class="navbar-brand" href="/#"> Brushfire</a>
        <div class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
            <li><a href="/videos">Videos</a></li>
          </ul>
        </div>
      </nav>
      <div class=" col-md-8 col-md-offset-2">
        <div class="jumbotron">
          <h1>Chad's Viral Videos Emporium</h1>
          <h2>Viral Videos since 2015</h2>
        </div>
      </div>
    </div>
  ...

Unsurprisingly, the Video.count() method returns the number of records in the video model. You need to figure out whether there are any videos already in the database, so you can just count the records. If the number is greater than zero, then you know you already have at least one video. So let’s take that for a spin. Open brushfire/config/bootstrap.js in Sublime and add the following code.

Figure 5.2. The .count() method calculates the number of records in the video model, and then, depending on the result, your code logs the appropriate message. Either way, you pass control back to Sails and it finishes lifting your app.