zoukankan      html  css  js  c++  java
  • [Node.js] Create a model to persist data in a Node.js LoopBack API

    In this lesson you will learn what a LoopBack model is, you will create a Product model using the LoopbBack CLI. The product model will be based off the built-in PersistedModel which gives it basic functionality like Create, Ready, Update, Delete and some more. Using the API Explorer you can interact with the new model, store, retrieve, edit and delete the product data.

    Create a REST API model:

    lb model

    Give the information needed, it can generate all the rest api.

    There are few files will be created.

    common/models/[model_name].js

    common/models/[model_name].json

    There is one file will be modified:

    server/model-config.json:

      "Product": {
        "dataSource": "db",
        "public": true
      }

    So if you want to remove the model, you can delete those generated stuff.

    If the data are stored in memory, it means once you restart the server, the data will lost, one way to keep the data for development:

    datasources.json:

    {
      "db": {
        "name": "db",
        "connector": "memory",
        "file": "db.json"
      }
    }

    Add "file" prop, it will store data inside the db.json.

  • 相关阅读:
    python学习之路-day1-python基础1
    JSON.NET基本使用
    tortoiseSVN 设置ignore
    一个简单的身份证校验
    一个HttpWebRequest工具类
    linq to NHibernate
    python-plot and networkx绘制网络关系图
    DDoS攻击及防御措施
    白帽子原则
    认识特洛伊木马
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6794439.html
Copyright © 2011-2022 走看看