Skip to content

awe v8 api

awe.media edited this page Oct 12, 2016 · 1 revision

What is awe_v8.js?

It's a simple datastore template that makes it easy to store, manage and extend collections of javascript objects in a consistent way.

Trust me, it's funkier than that sounds! 8)

Why is it called awe_v8?

Each datastore by default is designed to support a standard set of "8 verbs".

  • search
  • list
  • add
  • view
  • edit
  • update
  • delete
  • report

Through the magical process of simplification this translates in a subset of "6 implemented methods".

  • list
  • add
  • view
  • update
  • delete
  • report

search and edit are simply UIs that drive one of these 6 methods.

e.g. edit -> update or search -> list

There are also 3 utility methods:

  • error_handler
  • get_data
  • toString

How are errors handled?

In simple js mode a method call either returns undefined for an error or either an object or an array of 0 or more objects.

How do you use awe_v8?

create a awe_v8 datastore

  var my_datastore = new awe_v8();

add one object to your datastore

  console.log("add an object (return new id)");
  my_datastore.add({
    id: "test",
    some_data: "blah"
  });

add multiple objects to your datastore in one go

  console.log("add several objects (return new ids)");
  my_datastore.add([
    {
      id: "test2",
      some_data: "blahdeblah"
    },
    {
      new_param: 99,
      id: "test3",
      some_data: "hrmok"
    },
  ]);

list all objects currently in your datastore

  console.log("list all objects (return all objects)");
  my_datastore.list();

list all objects in SOAPjr format (see separate documentation for SOAPjr API)

  console.log("list all objects (return all objects in SOAPjr)");
  my_datastore.list({}, { output_format:"soapjr" });

view one object

  console.log("view an object (return one object)");
  my_datastore.view("test"); // simple
  my_datastore.view({ id: "test" }); // clear
  my_datastore.view({ id: "test" }, { output_format:"js" }); // explicit

update one object

  console.log("update an object (return updated fields)");
  my_datastore.update({
    data: {
      new_param: 34,
      some_data: "new_data",
    },
    where: {
      id: "test",
    }
  });

update many objects with the same values

  console.log("update 2 objects (return updated fields)");
  my_datastore.update({
    data: {
      new_param: 34,
      some_data: "new_data",
    },
    where: {
      id: ["test","another_test"],
    }
  });

update many objects with different values

  console.log("update 3 objects (return updated fields)");
  my_datastore.update([
    {
      data: {
        new_param: 34,
        some_data: "new_data",
      },
      where: {
        id: "test",
      }
    },
    {
      data: {
        new_param: 35,
        some_data: "more_new_data",
      },
      where: {
        id: ["test","another_test"],
      }
    },
  ]);

search for objects that fuzzy match a pattern

  console.log("list fuzzy matches (return roughly matching objects)");
  my_datastore.list({ id: "test" }, { limit: 10 });

search for objects that exactly match a pattern

  console.log("list exact matches (return exactly matching objects)");
  my_datastore.list({ exact: { id: "test2" } });

delete one object

  console.log("delete an object (return deleted ids)");
  my_datastore.delete({ id: "test2" });

delete multiple objects

  console.log("delete multiple objects (return deleted ids)");
  my_datastore.delete({ id: ["test1", "test2"] });

report metadata about this datastore

  console.log("report overview info (return a summary)");
  my_datastore.report();