Book Image

haXe 2 Beginner's Guide

5 (1)
Book Image

haXe 2 Beginner's Guide

5 (1)

Overview of this book

Table of Contents (21 chapters)
haxe 2
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

A concrete example of SPOD use


Let's see a concrete example of how to use that.

Set up a database in your MySQL server with a table named Users.

In this table, add the following three fields:

  1. id: This should be the Primary Key and have auto_increment, so that we don't have to worry about generating the Primary Keys.

  2. username: This should be a text; we will use it to store the user's username.

  3. password: This should be a text too; we will use it to store the user's password hash.

Setting the object

Now, let's create a User class reflecting those fields and useable as SPOD:

class User extends neko.db.Object
{
   public var id : Int;
   public var username : String;
   public var password : String;

   public static var manager = new neko.db.Manager<User>(User);
}

Note

Note: We are going to use the standard Manager.

Remember how we named our table Users and see how our class is named User? This makes perfect sense and it respects/accounts for what people are used to seeing. Still, we will need...