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 some dumb posts:
INSERT INTO 'expressCafe'.'Post' ( 'id' , 'title' , 'body' ) VALUES ( NULL , 'First Post', 'Hi, this is the first post of this blog!' ), ( NULL , 'Second post', 'This is the second post in a not so long series...