Skip to content

Instantly share code, notes, and snippets.

@jcward
Last active January 6, 2022 00:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcward/a2bc21576cba2587bba1d18b647c0f7d to your computer and use it in GitHub Desktop.
Save jcward/a2bc21576cba2587bba1d18b647c0f7d to your computer and use it in GitHub Desktop.
Haxe example SQLLite usage
# The sqllite database (written to the local directory as test.db)
# works (interoperably) in Neko, hxcpp (and many other platforms.) See:
# - https://api.haxe.org/sys/db/Connection.html
# - https://api.haxe.org/sys/db/ResultSet.html
# Compiles and runs Main.hx using neko
haxe -x Main
# Compiles and runs Main.hx using hxcpp
haxe -main Main -cpp out
./out/Main
# Also compatible with sqlite3 executable:
sqlite3 test.db "select * from artists_backup"
1|John
2|John
3|John
...
typedef ArtistsBackupRecord = {
artistid:Int,
name:String
}
class Main
{
public static function main()
{
var conn = sys.db.Sqlite.open("test.db");
var rs = conn.request('
CREATE TABLE IF NOT EXISTS artists_backup
(
artistid INTEGER PRIMARY KEY AUTOINCREMENT,
name NVARCHAR
);');
var rs = conn.request('
INSERT INTO artists_backup (name) VALUES ("John");');
var rs = conn.request('
SELECT * FROM artists_backup;');
trace('-- SELECT * FROM artists_backup');
for (record in (rs:Iterator<ArtistsBackupRecord>)) {
trace('${record.artistid}) ${record.name} --> ${ haxe.Json.stringify(record) }');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment