-
-
Save swayf/8fa58fc5fe83e850dd0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ; | |
import neko.Lib; | |
import sys.db.Manager; | |
import sys.db.Object; | |
import sys.db.Sqlite; | |
import sys.db.Types.SDate; | |
import sys.db.Types.SId; | |
import sys.db.Types.SNull; | |
import sys.db.Types.SString; | |
import sys.db.Types.SText; | |
/** | |
* ... | |
* @author | |
*/ | |
// SPOD example - old.haxe.org/manual/spod | |
// Neko/SQLite | |
class Main | |
{ | |
static function main() | |
{ | |
// Create the file my-database.sqlite if it doesn't exist and open a SQLite connection to it | |
var cnx = Sqlite.open('my-database.sqlite'); | |
// Initialize the sys.db.Manager that handles the SPOD stuff behind the scenes | |
Manager.cnx = cnx; | |
// Create the User table in my-database.sqlite if it doesn't exist | |
if ( !sys.db.TableCreate.exists(User.manager) ) sys.db.TableCreate.create(User.manager); | |
// create a new user | |
var u = new User(); | |
// set some parameters | |
u.name = "John Doe"; | |
u.birthday = Date.now(); | |
// store it in the db | |
u.insert(); | |
// fetch user with id # 1 | |
var u = User.manager.get(1); | |
if ( u == null ) throw "User #1 not found"; | |
// trace it | |
trace(u.name); | |
} | |
} | |
// User SPOD objcet that extends sys.db.Object | |
class User extends Object | |
{ | |
public var id : SId; // SPOD type for record Id | |
public var name : SString<32>; // SPOD type for strings | |
public var birthday : SDate; // SPOD type for date | |
public var phoneNumber : SNull<SText>; // SPOD tye for nullable variable-lenght text field | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment