Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
An ORM Tool for Titanium Appcelerator
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.settings
Resources
.gitignore
.project
CHANGELOG.txt
LICENSE
LICENSE.txt
README.markdown
manifest
tiapp.xml

README.markdown

yORM

Basics

yORM is an ORM built specifically for Titanium Appcelerator.

Usage

The entry point is BaseEntity. Write a javascript class that extends BaseEntity using prototypes. This class serves as your Entity class (or a table in database).

Sample Code

Include the single entity.js file

Ti.include('yORM/entity.js');

Declare a function like this

function UserEntity() {
    //add some of your own methods specific to User
};

Then extend BaseEntity like this

var dbName = "Your Database Name";

var tableName = "Your Table Name (used in the database)";

var fields = {

    'field1': 'SQLLite_DataType',

    'field2: 'SQLLite_DataType',

    'field3: 'SQLLite_DataType'

};

UserEntity.prototype = new BaseEntity(dbName, tableName, fields);

var user = new UserEntity();

The rest is easy

var user = new UserEntity();

user.field1 = 'field1_value';

user.field2 = 'field2_value';

user.field2 = 'field3_value';

user.save();

Ti.API.info(user.id);

Entity Methods.

save() - Insert into the table that this entity represents. Call this method after setting the values of the Entity. If you down't set any value, the default is null. The entity's id field is automatically updated with the id of inserted item.

removeAll() - Deletes from the table WITHOUT a where clause

remove() - Deletes from the table where id is the id of this entity

all() - Retrieves all records in the table

find(id, clauses) - Find a single record by id. Optionally you can specify clauses. clauses can be where, order, limit, etc clauses supported by SQLLite. Method always return a valid Entity. If there are no records found for the id, the Entity fields will be null.

findBy(fieldsAndValuesObject) - Find a single record. The where clause is generated from the object fieldsAndValuesObject. The return value is the first record found. If there are no records found, a valid entity will still be returned but the fields will be null. fieldsAndValuesObject is a javascript object. For example to find where name is 'Don' and age is 19 we will write new User().findBy({'name':'Don', 'age':19})

findAllBy(fieldsAndValuesObject) - Find all records. The where clause is as in findBy(fieldsAndValuesObject) method. The method returns a list. If there are no records found, an empty list is returned.

Something went wrong with that request. Please try again.