Giter VIP home page Giter VIP logo

db8's Introduction

DB8

DB8 is a storage method of webOS TV. DB8 is designed to meet the needs of robust, high-performance apps. DB8 is a service available on Luna Bus, and interfaces to an embedded JSON database. For more information about DB8, refer to DB8 Basics.

Getting Started

To put , delete, and merge data, create a kind using putKind() method first. The following code sample shows how to create a kind using the method.

  • private: The private parameter is available on webOS TV 3.0 or later. If the private parameter is true, when an app is uninstalled, the kind is also removed.
  • schema: The schema parameter is optional. If you define the schema, you must put the valid data that conforms to the schema format. For more information about the schema, refer to the Schema Enforcement page.
webOS.service.request("luna://com.palm.db", {
  method: "putKind",
  parameters: {
    id: "com.sample.db.owner:1",
    owner: "com.sample.db.owner",
    private: true,
    schema: {
      id: "com.sample.db.owner:1",
      type: "object",
      properties: {
        _kind: {
          type: "string",
          value: kindId,
        },
        number: {
          type: "integer",
          description: "number",
        },
        grade: {
          type: "string",
          description: "grade string",
        },
        isUsed: {
          type: "boolean",
          description: "flag",
        },
      },
    },
    indexes: [
      {
        name: "index0",
        props: [{ name: "number" }],
      },
      {
        name: "index1",
        props: [{ name: "grade" }, { name: "isUsed" }],
      },
      {
        name: "index2",
        props: [{ name: "isUsed" }],
      },
    ],
  },
  onSuccess: function (res) {
    clearLog;
    printLog("[putKind] onSuccess");
  },
  onFailure: function (res) {
    printLog("[putKind] onFailure");
    printLog("(" + res.errorCode + ") " + res.errorText);
    return;
  },
});

Finding Data with Queries

To find specific data from the database using queries, you must define indexes in the putKind() method. For more information about queries and indexes, refer to the Queries and Indexing page.

Three indexes were defined in the kind that was created in the code sample above. The following query examples show how to find data from the code sample.

find([{ prop: "number", op: ">", val: 3 }]);
find([
  { prop: "grade", op: "=", val: "A" },
  { prop: "isUsed", op: "=", val: false },
]);
find([{ prop: "isUsed", op: "=", val: true }]);

function find(query) {
  webOS.service.request("luna://com.palm.db", {
    method: "find",
    parameters: {
      query: {
        from: "com.sample.db.owner:1",
        where: query,
      },
    },
    onSuccess: function (res) {
      var result = res.results;
      console.log("[find] onSuccess:", result);
      // do something with result
    },
    onFailure: function (res) {
      console.log(res.errorCode, res.errorText);
      // do something on failure
    },
  });
}

Putting Permissions to Other Apps

To allow other apps' access to a kind, use putPermissions() method. The following example shows how to grant permission to other apps.

webOS.service.request("luna://com.palm.db", {
  method: "putPermissions",
  parameters: {
    permissions: [
      {
        operations: {
          read: "allow",
          create: "allow",
          update: "allow",
          delete: "allow",
        },
        object: "com.sample.db.owner:1",
        type: "db.kind",
        caller: "com.sample.db.*",
      },
    ],
  },
  onSuccess: function (res) {
    console.log("[putPermissions] onSuccess");
  },
  onFailure: function (res) {
    console.log("[putPermissions] onFailure:", res.errorCode, res.errorText);
  },
});

Putting Data with Reserved IDs

After reserving data IDs using reserveIds() method, you can put, get, delete data by the IDs. The following example shows how to reserve IDs.

function reserveIds(count) {
  webOS.service.request("luna://com.palm.db", {
    method: "reserveIds",
    parameters: {
      count: count,
    },
    onSuccess: function (res) {
      let result = res.ids;
      console.log("[reserveIds] onSuccess:", result);
      return result;
    },
    onFailure: function (res) {
      console.log("[reserveIds] onFailure:", res.errorCode, res.errorText);
      return [];
    },
  });
}

Result in the webOS TV

You can install sample apps and see the results in the webOS TV or webOS TV Simulator as below image.

com.sample.db.owner.PNG com.sample.db.user.PNG

Do's and Don'ts

  • Do test these sample apps on your webOS TV or webOS TV Simulator.

  • Do update the webOSTV.js library when the new version is released.

  • The 'com.sample.db.user' sample app does not work properly if the 'com.sample.db.owner' sample app has not created a kind or granted the kind's permission.

db8's People

Contributors

sangrokkang avatar haeun-p avatar loegnah avatar

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.