Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for jspm package manager #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ the structured data is stored as serialized JSON in localStorage or sessionStora
# Installation
`bower install localstoragedb`

`jspm install github:uelarn/localstoragedb`

# Run Test Cases

```shell
Expand Down
103 changes: 103 additions & 0 deletions dist/amd/localStorageDB.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* Created by [BombSquad Inc](http://www.bmbsqd.com)
* User: Andy Hawkins
* Date: 6/29/15
* Time: 11:19 AM
*/
// uelarn 11.10.15: Modified to support amd with jspm package manager, + params in queryAll optional

declare module 'localStorageDB' {

export type localStorageDB_callback = (object: localStorageDB_fields) => localStorageDB_dynamicFields;
export type localStorageDB_callbackFilter = (object: localStorageDB_fields) => boolean;

export class localStorageDB {
constructor(database_name: string, storage_engine?: string); // Constructor: storage_engine can either be localStorage (default) or sessionStorage
isNew(): boolean; // Returns true if a database was created at the time of initialisation with the constructor
drop(): void; // Deletes a database, and purges it from localStorage
tableCount(): number; // Returns the number of tables in a database
commit(): boolean; // Commits the database to localStorage. Returns true if successful, and false otherwise (highly unlikely)
serialize(): string; // Returns the entire database as serialized JSON
tableExists(table: string): boolean; // Checks whether a table exists in the database
tableFields(table: string): string[]; // Returns the list of fields of a table
createTable(table: string, fields: string[]); // Creates a table - fields is an array of string fieldnames. 'ID' is a reserved fieldname.
createTableWithData(table: string, rows: { [T: string]: any }[]);
/*
Creates a table and populates it
rows is an array of object literals where each object represents a record
[{field1: val, field2: val}, {field1: val, field2: val}]
*/
alterTable(table: string, new_fields: string[] | string, default_values: localStorageDB_dynamicFields | string);
/*
Alter a table
- new_fields can be a array of columns OR a string of single column.
- default_values (optional) can be a object of column's default values OR a default value string for single column for existing rows.
*/
dropTable(table: string): void; // Deletes a table from the database
truncate(table: string): void; // Empties all records in a table and resets the internal auto increment ID to 0
columnExists(table: string, field: string): boolean; // Checks whether a column exists in database table.
rowCount(table: string): number; // Returns the number of rows in a table
insert(table: string, data: { [T: string]: any }): number;
/*
Inserts a row into a table and returns its numerical ID
- data is an object literal with field-values
every row is assigned an auto-incremented numerical ID automatically
*/
query(table: string, query?: { [T: string]: any }, limit?: number, start?: number, sort?: any): localStorageDB_fields[];
/* DEPRECATED
Returns an array of rows (object literals) from a table matching the query.
- query is either an object literal or null. If query is not supplied, all rows are returned
- limit is the maximum number of rows to be returned
- start is the number of rows to be skipped from the beginning (offset)
- sort is an array of sort conditions, each one of which is an array in itself with two values
- distinct is an array of fields whose values have to be unique in the returned rows
Every returned row will have it's internal auto-incremented id assigned to the variable ID
*/
queryAll(table: string, params?: localStorageDB_queryParams): localStorageDB_fields[];
/*
Returns an array of rows (object literals) from a table matching the query.
- query is either an object literal or null. If query is not supplied, all rows are returned
- limit is the maximum number of rows to be returned
- start is the number of rows to be skipped from the beginning (offset)
- sort is an array of sort conditions, each one of which is an array in itself with two values
- distinct is an array of fields whose values have to be unique in the returned rows
Every returned row will have it's internal auto-incremented id assigned to the variable ID
*/
update(table: string, query: localStorageDB_dynamicFields | localStorageDB_callbackFilter, update?: localStorageDB_callback): number;
/*
Updates existing records in a table matching query, and returns the number of rows affected
- query is an object literal or a function. If query is not supplied, all rows are updated
- update_function is a function that returns an object literal with the updated values
*/
insertOrUpdate(table: string, query: localStorageDB_dynamicFields | localStorageDB_callbackFilter, data: localStorageDB_fields): number;
/*
Inserts a row into a table if the given query matches no results, or updates the rows matching the query.
- query is either an object literal, function, or null.
- data is an object literal with field-values
Returns the numerical ID if a new row was inserted, or an array of IDs if rows were updated
*/
deleteRows(table: string, query: localStorageDB_dynamicFields | localStorageDB_callbackFilter): number;
/*
Deletes rows from a table matching query, and returns the number of rows deleted
- query is either an object literal or a function. If query is not supplied, all rows are deleted
*/
}

export interface localStorageDB_fields extends localStorageDB_dynamicFields {
ID: number;
}

export interface localStorageDB_dynamicFields {
[T: string]: any;
}

export interface localStorageDB_queryParams {
query?: { [T: string]: any }; // - query is either an object literal or null. If query is not supplied, all rows are returned
limit?: number; // - limit is the maximum number of rows to be returned
start?: number; // - start is the number of rows to be skipped from the beginning (offset)
sort?: { [T: string]: any }[]; // - sort is an array of sort conditions, each one of which is an array in itself with two values
distinct?: string[]; // - distinct is an array of fields whose values have to be unique in the returned rows
}

//export = localStorageDB;
}
Loading