knadh / localStorageDB

A simple database layer for localStorage and sessionStorage for creating structured data in the form of databases and tables
http://nadh.in/code/localstoragedb
814 stars 128 forks source link

Implemented two new features. #31

Closed a904guy closed 10 years ago

a904guy commented 10 years ago

Added start to query function for easy pagination. ( limit, start )

In Example: limit = per_page. start = (page - 1) * per_page

Also added tableKeys function to return the fields of a table.

Updated README with documentation as well.

a904guy commented 10 years ago

I have an addition sorting function (iterates through select results) completed as well.

knadh commented 10 years ago
a904guy commented 10 years ago

Fair enough, but the existing regex doesn't allow numeric, a integer like murmurhash hash wasn't being allowed as a table name because it has no match function. Hence casting into String first.

(Removed CRC32 (alphanumeric) comment, was using murmurhash)

knadh commented 10 years ago

@a904guy, can you post a couple examples of this please? Thanks.

a904guy commented 10 years ago

@knadh, http://jsfiddle.net/RaL7b/1/

a904guy commented 10 years ago

@knadh, Using my pull commit: http://jsfiddle.net/V7egC/

a904guy commented 10 years ago

I know its not perfect, needs validation against NaN,undefined,null, etc

knadh commented 10 years ago

I see what you mean now. Casting all inputs to string and then doing the regex should cover all cases then. Like you said, the non-regex route leaves a bunch of a exceptions to be dealt with. Will commit with casting.

a904guy commented 10 years ago

Excellent. Thank you.

I have a small question, why is it that you don't want spaces in field names? Just so it makes it appear more like a database, or is a programmatic reason?

I only ask because with the storage being JSON, spaces in database,tables,field names shouldn't matter. So for a dynamic backend data system being used to store data with this, you have to pre-filter your data in/out if they contain spaces.

In example: I was using this make a dynamic table rendering for an analytical system and the table fields (thead:tr:th) contained spaces occasionally, which was my reason for needing it.

knadh commented 10 years ago

Not allowing spaces in db/table/field names is for the sake of convention, readability, and consistency.

As an example, the way it is right now, one can do row.field_name without second thoughts. If spaces and other special characters were allowed, then it'd have to be row["field name"].

knadh commented 10 years ago

https://github.com/knadh/localStorageDB/commit/6f353d15c18c639b51672b2d15214478d43fdc90 adds string casting to name validation