Packagecom.memamsa.airdb
Classpublic class DB

DB constants, helpers and utilities.

Use DB.initDB in your application startup code to name and initialize the database file.

Use Modeler sub-classes as Object Relational Models with base-class supported create, update, delete and query operations.

Use a Migrator member within your models for schema definition, and migrations.

Specify associations as class meta-data and add appropriate schema support to get object relationships through the Associator.

See also

Modeler
Migrator
Associator


Public Methods
 MethodDefined by
  
execute(sql:String):SQLResult
[static] Specify a SQL statement to be executed directly
DB
  
existsTable(name:String):Boolean
[static] Check if the specified table exists
DB
  
fieldMap(fieldSpec:Array):String
[static] Map a DB field as specified in migration directives into an appropriate DB-specific CREATE statement clause after processing field type and column options.
DB
  
getConnection(dbname:String = null):SQLConnection
[static] Obtain and cache a connection to the database.
DB
  
getSchema(reloadSchema:Boolean = false):SQLSchemaResult
[static] Get and cache the overall database schema.
DB
  
getTableSchema(name:String, refresh:Boolean = false):SQLTableSchema
[static] Get the schema for the specified table.
DB
  
initDB(dbname:String):void
[static] Initialize database for use within the application.
DB
  
mapForeignKey(klass:*):String
[static] Map a class to its default foreign key name in another table.
DB
  
mapJoinTable(klass1:*, klass2:*):String
[static] Map two classes into a join table name for representing the many-many relationship between them.
DB
  
mapTable(klass:*):String
[static] Map a class to a default table name through pluralized inflection.
DB
  
migrate(mobj:IMigratable):void
[static] Request migration for a particular model.
DB
  
migrateAll():Boolean
[static] Unsupported.
DB
  
sqlMap(value:Object):String
[static] Map an object to its SQL representation appropriate for queries.
DB
Public Constants
 ConstantDefined by
  Field : Object
[static]
DB
Method detail
execute()method
public static function execute(sql:String):SQLResult

Specify a SQL statement to be executed directly

Parameters
sql:String — A valid SQL statement

Returns
SQLResult — A SQLResult
existsTable()method 
public static function existsTable(name:String):Boolean

Check if the specified table exists

Parameters
name:String — The table name to check

Returns
Booleantrue if table exists, false otherwise
fieldMap()method 
public static function fieldMap(fieldSpec:Array):String

Map a DB field as specified in migration directives into an appropriate DB-specific CREATE statement clause after processing field type and column options.

Parameters
fieldSpec:Array — An Array [name, type, options]

Returns
String — A SQL field clause for use in CREATE TABLE
getConnection()method 
public static function getConnection(dbname:String = null):SQLConnection

Obtain and cache a connection to the database. We use synchronous open.

Parameters
dbname:String (default = null) — (optional) The name for the database file

Returns
SQLConnection
getSchema()method 
public static function getSchema(reloadSchema:Boolean = false):SQLSchemaResult

Get and cache the overall database schema.

Parameters
reloadSchema:Boolean (default = false) — (optional) Set to true to ignore the cached schema and force a reload.

Returns
SQLSchemaResult — The SQL schema for the database.
getTableSchema()method 
public static function getTableSchema(name:String, refresh:Boolean = false):SQLTableSchema

Get the schema for the specified table.

Parameters
name:String — The table name for which to get the schema
 
refresh:Boolean (default = false) — If true force reload the DB schema.

Returns
SQLTableSchema — The SQL schema for the table. Returns null if the table does not exist in the database.
initDB()method 
public static function initDB(dbname:String):void

Initialize database for use within the application. The database is stored in the AIR.File.applicationStorageDirectory

Parameters
dbname:String — The name for the SQLite database file.

See also

flash.filesystem.File.applicationStorageDirectory
mapForeignKey()method 
public static function mapForeignKey(klass:*):String

Map a class to its default foreign key name in another table.

Parameters
klass:* — The model class (Class or Modeler)

Returns
String — The default foreign key name

Example
Foreign key for the Author model
  mapForeignKey(Author);    // ==> "author_id"
  

mapJoinTable()method 
public static function mapJoinTable(klass1:*, klass2:*):String

Map two classes into a join table name for representing the many-many relationship between them.

The table names are sorted alphabetically so as to ensure the same join table name for a given pair of classes, regardless of the parameter order during the function call.

Parameters
klass1:* — One of the models (Class or Modeler)
 
klass2:* — The other model class

Returns
String — A default join table name

See also

mapTable

Example
A blog post can have many categories, and a category can apply to many blog posts.
  mapJoinTable(Post, Category);     // ==> "categories_posts"
  

mapTable()method 
public static function mapTable(klass:*):String

Map a class to a default table name through pluralized inflection.

Parameters
klass:* — A Class or Modeler

Returns
String — The default table name mapping

See also

migrate()method 
public static function migrate(mobj:IMigratable):void

Request migration for a particular model. No external usage required.

Parameters
mobj:IMigratable

See also

migrateAll()method 
public static function migrateAll():Boolean

Unsupported. Do Not Use. Migrations are automatically carried out as and when required. Future Use: Force all migrations to run at once.

Returns
Boolean
sqlMap()method 
public static function sqlMap(value:Object):String

Map an object to its SQL representation appropriate for queries.

Deperecation Notice: This method will be removed when we switch to parameterized SQL operations.

Parameters
value:Object — An Object (String or Date)

Returns
String
Constant detail
Fieldconstant
public static const Field:Object