O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action—Creating our SPOD class

First, let's create a very simple SPOD class representing our blog posts.

Add this code to Post.hx:

class Post extends neko.db.Object
{
public var id : Int;
public var title : String;
public var body : String;
public static var manager = new neko.db.Manager<Post>(Post);
}

You also have to create the corresponding table in your SQL database. You can create it and name it "myBlog".

In order to do so, you can use the following SQL statement:

CREATE TABLE 'Post' (
'id' INT NOT NULL AUTO_INCREMENT,
'title' TEXT NOT NULL,
'body' LONGTEXT NOT NULL,
PRIMARY KEY ( 'id' )
) ENGINE = MYISAM;

Once you have done this, our SQL database is set up correctly and we have objects to work with. You may want to populate it with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required