Last active
January 6, 2022 00:45
-
-
Save jcward/a2bc21576cba2587bba1d18b647c0f7d to your computer and use it in GitHub Desktop.
Haxe example SQLLite usage
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
# 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 | |
... |
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
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