- Smart Personal Cloud

Database Access

1

Database access is an important aspect of online application development. Star Script has a built-in object database. For simple tasks, users can directly use the object database to avoid any object relational mapping. For complex tasks, or integration with legacy systems, Star Script provides a wrapper on top of the JDBC API. Users can connect to any database with a JDBC driver.

The MyEzApp site does not support the JDBC wrapper. Because of that, the only way for MyEzApp users to persist data is using files or the built-in database.

2

The built-in database supports four statements: - save - load - select, and - delete statements

Save

The save statement allows you to save an object to a database at a specific path. The syntax of the save statement is:

save <object expression> to <path>

The object parameter is required. For example,

class person   var firstname as string   var lastname as string end var p = new person() save p
Load

Load statement allows you to load an object with the following syntax:

load <class name> withid <id expression> from <path>

The following is a breakdown of the statement: - the class name parameter is required, - the id expression parameter is required, and - the path parameter is optional.

The object loaded from the load statement must be assigned to a variable immediately. For example

class person   var firstname as string   var lastname as string end var p = load person withid "0" p.lastname, p.firstname       // this should print out the person's name // or var p1 as person p1 = load person withid "0"
Select

The select statement allows you to find object from database. The syntax of the select statement is:

select <class name> from <path> where <filter> order by <field names> <asc or dsc>

The following is a breakdown of the statement: - the class name parameter is required, - the path parameter is optional, - the filter parameter is optional, - the field names parameter is optional, and - the asc or dsc parameter is optional

The filter parameter is a Boolean expression. This expression will be evaluated against every object in the database. If the filter expression evaluates to ture, the object will be added to the select result. If the expression evaluates to false, the object will not be added to the select result.

The select statement will load an array of objects from database. The result must be assigned to a variable immediately. Below is an example of a select statement assignment to a variable:

class person   var firstname as string   var lastname as string end var p = select person          // the type of p is "person[]" we have p.length persons.      // this should output "we have 2 persons." p[1].lastname, p[1].firstname  // this should print out the person's name

As a shortcut, if you just want to load one object from the database, you can use the syntax:

select first <class name> from <path> where <filter>

Select first statement will return you a single object with proper type. For example,

class person   var firstname as string   var lastname as string end var p = select first person where oid == "0"    // the type of p is "person" p.lastname, p.firstname                         // this should print out the person's name
Delete

The delete statement allows you to remove an object from the database. The syntax of the delete statement is:

delete <class name> withid <id expression> from <path>

The following is a breakdown of the statement: - the class name parameter is required, - the id expression parameter is required, and - the path parameter is optional. For example,

class person   var firstname as string   var lastname as string end delete person withid "0"
3

Using the Files Manager, you can browse the data saved in your database.