Getting Started With Sqlite


The "Test" class connects to a Sqlite database, creates the "User" table (based off the User class below), inserts two users and closes the connection.

Code (Test.hx):

import sys.db.Types;

class Test {
    static function main() {
        // Open a connection
        var cnx ="mybase.db");

        // Set as the connection for our SPOD manager
        sys.db.Manager.cnx = cnx;

        // Create the "user" table

        // Set up our first two users
        var user1 = new User(); = "Jason O'Neil";
        user1.birthday = new Date(1987,10,16,0,0,0);
        user1.phoneNumber = "(08) 9350 0000";

        var user2 = new User(); = "Anna O'Neil";
        user2.birthday = new Date(1990,02,21,0,0,0);
        user2.phoneNumber = null;

        // Insert these two users into our database
        // Close the connection

class User extends sys.db.Object {
    public var id : SId;
    public var name : SString<32>;
    public var birthday : SDate;
    public var phoneNumber : SNull<SText>;

To compile and execute in one step:

haxe -D spod_macro -x Test.hx
version #14173, modified 2012-05-29 03:40:56 by jason