-
Notifications
You must be signed in to change notification settings - Fork 0
API Cheat Sheet [store5]
Working with data storage on web technology
For using store5
module. Let's import this module into your application.
import {store5} from '@bapquad/element5'
Open the database simulator.
Parameter
-
type:string
- The types of storage engine. Required
Return
Returns the storage engine.
Storage engine constants
-
cookie_ds
- Data stored base on cookie. It returns the ExpireData Simulator object. -
local_ds
- Data stored base on local storage interfaces. It returns the LocalData Simulator object -
session_ds
- Data stored base on session storage interfaces. It returns the SessionData Simulator object -
indexed_db
- Data stored base on IndexedDB interfaces. It returns the IndexedDB Simulator object, It must be declared with a database name.
Example
import {store5} from '@bapquad/element5'
let storage = store5.Open("cookie_ds");
// Print the storage engine
console.log(storage);
Manages the ExpireData
Simulator storage engine.
Create the public variable. This can access everywhere in the application.
Parameter
-
name:string
- The data name. Required -
value:any
- The data value. Required -
period:number
- The period time in the second unit. Optional
Return
Returns the ExpireDataRecordItem
object.
Example
import {store5} from '@bapquad/element5'
let ds = store5.Open("cookie_ds");
ds.public("username", "John Paul', 24*60*60);
Create the private variable. This can access in the current branch only.
Parameter
-
name:string
- The data name. Required -
value:any
- The data value. Required -
period:number
- The period time in the second unit. Optional
Return
Returns the ExpireDataRecordItem
object.
Example
In the ./sub_branch/index.html
file.
import {store5} from '@bapquad/element5'
let ds = store5.Open("cookie_ds");
ds.private("username", "John Paul", 24*60*60);
// Print the data value
console.log(ds.private("username"));
In the ./index.html
file.
import {store5} from '@bapquad/element5'
let ds = store5.Open("cookie_ds");
// Print the data
console.log(ds.private("username"));
Manipulating the records of ExpireData Simulator storage engine.
Get value of the cookie variable.
Parameter
- Has no parameter.
Return
Returns the data value.
Example
import {store5} from '@bapquad/element5'
let ds = store5.Open("cookie_ds");
let item = ds.private("username", "John Paul", 60));
// Print the data value
console.log(item.GetValue());
Set value to the cookie variable.
Parameter
-
value:any
- The data value. Required
Return
Returns the void value.
Example
import {store5} from '@bapquad/element5'
let ds = store5.Open("cookie_ds");
let item = ds.private("username", "John Paul", 60));
item.SetValue("Magaret");
// Print the data value
console.log(item.GetValue());
Destroy the cookie variable.
Parameter
- Has no parameter.
Return
Returns the void value.
Example
import {store5} from '@bapquad/element5'
let ds = store5.Open("cookie_ds");
let item = ds.private("username", "John Paul", 60));
item.SetValue("Magaret");
item.Destroy();
// Print the data value
console.log(item.GetValue());
Manages the LocalData
Simulator storage engine.
Create the public variable. This can access everywhere in the application.
Parameter
-
name:string
- The data name. Required -
value:any
- The data value. Required
Return
Returns the LocalDataRecordItem
object.
Example
import {store5} from '@bapquad/element5'
let ds = store5.Open("local_ds");
let item = ds.public("username", "John Paul");
// Print the localdata item
console.log(item);
Create the private variable. This can access in the current branch only.
Parameter
-
name:string
- The data name. Required -
value:any
- The data value. Required
Return
Returns the LocalDataRecordItem
object.
Example
In the ./sub_branch/index.html
file.
import {store5} from '@bapquad/element5'
let ds = store5.Open("local_ds");
ds.private("username", "John Paul");
// Print the data value
console.log(ds.private("username"));
In the ./index.html
file.
import {store5} from '@bapquad/element5'
let ds = store5.Open("local_ds");
// Print the data value
console.log(ds.private("username"));
Manipulating the records of LocalData Simulator storage engine.
Retrieves the value of the variable.
Parameter
- Has no parameter.
Return
Returns the data value.
Example
import {store5} from '@bapquad/element5'
let ds = store5.Open("local_ds");
let item = ds.public("username", "John Paul");
// Print the data value
console.log(item.GetValue());
Sets the value to the variable.
Parameter
-
value:any
- The data value. Required
Return
Returns the LocalDataRecordItem
object.
Example
import {store5} from '@bapquad/element5'
let ds = store5.Open("local_ds");
let item = ds.public("username", "John Paul");
item.SetValue("Magaret");
// Print the data value
console.log(item.GetValue());
Removes the variable from LocalDB database.
Parameter
- Has no parameter.
Return
Returns the void value.
Example
import {store5} from '@bapquad/element5'
let ds = store5.Open("local_ds");
let item = ds.public("username", "John Paul");
item.Remove();
// Print the data value
console.log(item.GetValue());
Manages the SessionData
Simulator storage engine.
Create the public variable in `SessionStorage. This can access everywhere in the application.
Parameter
-
name:string
- The data name. Required -
value:any
- The data value. Required
Return
Returns the SessionDataRecordItem
object.
Example
import {store5} from '@bapquad/element5'
let ds = store5.Open("session_ds");
let item = ds.public("username", "John Paul");
// Print the sessiondata item
console.log(item);
Create the private variable. This can access in the current branch only.
Parameter
-
name:string
- The data name. Required -
value:any
- The data value. Required
Return
Returns the SessionDataRecordItem
object.
Example
In the ./sub_branch/index.html
file.
import {store5} from '@bapquad/element5'
let ds = store5.Open("session_ds");
ds.private("username", "John Paul");
// Print the value
console.log(ds.private("username"));
In the ./index.html
file.
import {store5} from '@bapquad/element5'
let ds = store5.Open("session_ds");
// Print the value
console.log(ds.private("username"));
Manipulating the records of SessionData Simulator storage engine.
Retrieves the value of the variable.
Parameter
- Has no parameter.
Return
Returns the data value.
Example
import {store5} from '@bapquad/element5'
let ds = store5.Open("session_ds");
let item = ds.public("username", "John Paul");
// Print the data
console.log(item.GetValue());
Sets the value to the variable.
Parameter
-
value:any
- The data value. Required
Return
Returns the SessionDataRecordItem
object.
Example
import {store5} from '@bapquad/element5'
let ds = store5.Open("session_ds");
let item = ds.public("username", "John Paul");
item.SetValue("Magaret"));
// Print the data
console.log(item.GetValue());
Removes the variable from SessionStorage.
Parameter
- Has no parameter.
Return
Returns the void value.
Example
import {store5} from '@bapquad/element5'
let ds = store5.Open("session_ds");
let item = ds.public("username", "John Paul");
item.Remove();
// Print the value
console.log(item.GetValue());
Manages the IndexedDB simulator storage engine.
Constructs a database with the schema of tables. It updates when the database change the version.
Parameters
-
tables[,...]:list
- List of schema arguments. Required
Return
Returns the IDBOpenDBRequest
object with IndexedDB Simulator extensions.
Example
import {store5} from '@bapquad/element5'
var db = store5.Open("indexed_db", "program", 1);
db.Schema({
name: "scores",
primaryKey: "id",
active: true,
autoIncrement: true,
fields: [
{
name: "score",
data: ["playerName", "score"],
type: {"unique" : true}
},
],
});
Manipulating the database of IndexedDB Simulator storage engine.
Retrieves the table (the ObjectStore
Interface).
Parameter
-
name:string
- The name of table. Required
Return
Returns the IDBObjectStore
object.
Example
import {store5} from '@bapquad/element5'
var store = store5.Open("indexed_db", "program", 1);
store.Schema({
name: "scores",
primaryKey: "id",
active: true,
autoIncrement: true,
fields: [
{
name: "score",
data: ["playerName", "score"],
type: {"unique" : true}
},
],
});
store.success = (e) =>
{
console.log(store.database.From("scores"));
}
Retrieves the table (the ObjectStore
Interface).
Parameter
-
name:string
- The name of table. Required
Return
Returns the IDBObjectStore
object.
Example
import {store5} from '@bapquad/element5'
var store = store5.Open("indexed_db", "program", 1);
store.Schema({
name: "scores",
primaryKey: "id",
active: true,
autoIncrement: true,
fields: [
{
name: "score",
data: ["playerName", "score"],
type: {"unique" : true}
},
],
});
store.success = (e) =>
{
console.log(store.database.Table("scores"));
}
The IDBObjectStore
interface of the IndexedDB API represents an object store in a database. Records within an object store are sorted according to their keys. This sorting enables fast insertion, look-up, and ordered retrieval.
[Read Only] A list of the names of indexes on objects in this object store.
Value
A DOMStringList
.
Example
import {store5} from '@bapquad/element5'
var store = store5.Open("indexed_db", "program", 1);
store.Schema({
name: "scores",
primaryKey: "id",
active: true,
autoIncrement: true,
fields: [
{
name: "score",
data: ["playerName", "score"],
type: {"unique" : true}
},
],
});
store.success = (e) =>
{
console.log(store.database.Table("scores").indexNames);
}
[Read Only] The autoIncrement read-only property of the IDBObjectStore
interface returns the value of the auto increment flag for this object store.
Value
The Boolean value.
Example
import {store5} from '@bapquad/element5'
var store = store5.Open("indexed_db", "program", 1);
store.Schema({
name: "scores",
primaryKey: "id",
active: true,
autoIncrement: true,
fields: [
{
name: "score",
data: ["playerName", "score"],
type: {"unique" : true}
},
],
});
store.success = (e) =>
{
console.log(store.database.Table("scores").autoIncrement);
}
[Read Only] The key path of this object store. If this attribute is null, the application must provide a key for each modification operation.
Value
The any value.
Example
import {store5} from '@bapquad/element5'
var store = store5.Open("indexed_db", "program", 1);
store.Schema({
name: "scores",
primaryKey: "id",
active: true,
autoIncrement: true,
fields: [
{
name: "score",
data: ["playerName", "score"],
type: {"unique" : true}
},
],
});
store.success = (e) =>
{
console.log(store.database.Table("scores").keyPath);
}
The name property of the IDBObjectStore
interface indicates the name of this object store.
Value
A DOMString
containing the object store's name.
Example
import {store5} from '@bapquad/element5'
var store = store5.Open("indexed_db", "program", 1);
store.Schema({
name: "scores",
primaryKey: "id",
active: true,
autoIncrement: true,
fields: [
{
name: "score",
data: ["playerName", "score"],
type: {"unique" : true}
},
],
});
store.success = (e) =>
{
console.log(store.database.Table("scores").name);
}
[Read Only] The transaction read-only property of the IDBObjectStore
interface returns the transaction object to which this object store belongs.
Value
An IDBTransaction
object.
Example
import {store5} from '@bapquad/element5'
var store = store5.Open("indexed_db", "program", 1);
store.Schema({
name: "scores",
primaryKey: "id",
active: true,
autoIncrement: true,
fields: [
{
name: "score",
data: ["playerName", "score"],
type: {"unique" : true}
},
],
});
store.success = (e) =>
{
console.log(store.database.Table("scores").transaction);
}
An IDBRequest
object on which subsequent events related to this operation are fired.
Parameter
-
value:object
- The desired data object. Required
Return
Returns an IDBRequest
object on which subsequent events related to this operation are fired.
Example
import {store5} from '@bapquad/element5'
var store = store5.Open("indexed_db", "program", 1);
store.Schema({
name: "scores",
primaryKey: "id",
active: true,
autoIncrement: true,
fields: [
{
name: "score",
data: ["playerName", "score"],
type: {"unique" : true}
},
],
});
store.success = (e) =>
{
console.log(store.database.Table("scores"));
let item = {
playerName: "Walk dog",
playerBirth: "02/09/1987"
};
store.database.Table("scores").add(item);
}
Creates and immediately returns an IDBRequest
object, and clears this object store in a separate thread. This is for deleting all the current data out of an object store.
Parameter
- Has no parameter.
Return
Returns an IDBRequest
object on which subsequent events related to this operation are fired.
Example
import {store5} from '@bapquad/element5'
var store = store5.Open("indexed_db", "program", 1);
store.Schema({
name: "scores",
primaryKey: "id",
active: true,
autoIncrement: true,
fields: [
{
name: "score",
data: ["playerName", "score"],
type: {"unique" : true}
},
],
});
store.success = (e) =>
{
console.log(store.database.Table("scores"));
let item = {
playerName: "Walk dog",
playerBirth: "02/09/1987"
};
store.database.Table("scores").clear();
}
Returns an IDBRequest
object, and, in a separate thread, returns the total number of records that match the provided key or IDBKeyRange
. If no arguments are provided, it returns the total number of records in the store.
Parameter
- Has no parameter.
Return
Returns an IDBRequest
object on which subsequent events related to this operation are fired.
Example
import {store5} from '@bapquad/element5'
var store = store5.Open("indexed_db", "program", 1);
store.Schema({
name: "scores",
primaryKey: "id",
active: true,
autoIncrement: true,
fields: [
{
name: "score",
data: ["playerName", "score"],
type: {"unique" : true}
},
],
});
store.success = (e) =>
{
let request = store.database.Table("scores").count();
request.onsuccess = function() {
console.log(request.result);
}
}
Deletes the specified record or records.
Parameter
-
key:any
- The key object record. Required
Return
Returns an IDBRequest
object on which subsequent events related to this operation are fired. The request.result attribute is set to undefined
.
Example
import {store5} from '@bapquad/element5'
var store = store5.Open("indexed_db", "program", 1);
store.Schema({
name: "scores",
primaryKey: "id",
active: true,
autoIncrement: true,
fields: [
{
name: "score",
data: ["playerName", "score"],
type: {"unique" : true}
},
],
});
store.success = (e) =>
{
console.log(store.database.Table("scores"));
let item = {
playerName: "Walk dog",
playerBirth: "02/09/1987"
};
store.database.Table("scores").add(item);
store.database.Table("scores").delete(1);
}
Returns an IDBRequest
object, and, in a separate thread, returns the object store selected by the specified key. This is for retrieving specific records from an object store.
Parameter
-
key:any
- The key object record. Required
Return
Returns an IDBRequest
object on which subsequent events related to this operation are fired.
Example
import {store5} from '@bapquad/element5'
var store = store5.Open("indexed_db", "program", 1);
store.Schema({
name: "scores",
primaryKey: "id",
active: true,
autoIncrement: true,
fields: [
{
name: "score",
data: ["playerName", "score"],
type: {"unique" : true}
},
],
});
store.success = (e) =>
{
console.log(store.database.Table("scores"));
let item = {
playerName: "Walk dog",
playerBirth: "02/09/1987"
};
store.database.Table("scores").add(item);
let request = store.database.Table("scores").get(1);
request.onsuccess = function()
{
let record = request.result;
console.log(item, record);
}
}
Retrieves all records in object store.
Parameter
- Has no parameter.
Return
Returns an IDBRequest
object on which subsequent events related to this operation are fired.
Example
import {store5} from '@bapquad/element5'
var store = store5.Open("indexed_db", "program", 1);
store.Schema({
name: "scores",
primaryKey: "id",
active: true,
autoIncrement: true,
fields: [
{
name: "score",
data: ["playerName", "score"],
type: {"unique" : true}
},
],
});
store.success = (e) =>
{
console.log(store.database.Table("scores"));
let item = {
playerName: "Walk dog",
playerBirth: "02/09/1987"
};
store.database.Table("scores").add(item);
let request = store.database.Table("scores").getAll();
request.onsuccess = function()
{
let records = request.result;
console.log(item, records);
}
}
Updates a given record in a database, or inserts a new record if the given item does not already exist.
Parameter
-
data:object
- The update data. Required -
key:number
- The key of primary key. Required -
success:callback
- The callback function called when the data had been updated. Optional.
Return
Returns an IDBObjectStore
object.
Example
import {store5} from '@bapquad/element5'
var store = store5.Open("indexed_db", "program", 1);
store.Schema({
name: "scores",
primaryKey: "id",
active: true,
autoIncrement: true,
fields: [
{
name: "score",
data: ["playerName", "score"],
type: {"unique" : true}
},
],
});
store.success = (e) =>
{
console.log(store.database.Table("scores"));
let item = {
playerName: "Walk dog",
playerBirth: "02/09/1987"
};
store.database.Table("scores").add(item);
store.database.Table("scores").update({playerName: "Walk dog"}, 1);
}
Bapquad Games since 2015
- Get Started
- Working with DOM
- Constructing the StyleSheet
- Working with Sprite
- Working with Timeline
- Working with Scroller
- Working with Camera
- Working with Microphone
- Making the Ajax Request
- Opening a Websocket
- Working with Storage
- Checking User Agent
- Working with GPS
- Working with Router
- Playing the Stream