A GDNative SQLite wrapper module for Godot 3.0
- Compile Godot 3.0
- Get the GodotNativeTools sources:
$ cd gd-sqlite/
$ git clone https://github.com/GodotNativeTools/godot_headers.git
$ git clone https://github.com/GodotNativeTools/godot-cpp.git
- Link godot source
$ ln -s [/path/to/godot/] godot_fork
[gd-sqlite]
├──godot_fork -> [/path/to/godot/]
├──cpp_bindings/
├──godot_headers/
└──src/
$ cd cpp_bindings
$ scons godotbinpath="../godot_fork/bin/" headers="../godot_headers/" p=linux generate_bindings=yes
- Copy libraries into libs dir
$ cd ..
$ mkdir lib
$ cp cpp_bindings/bin/libgodot_cpp_bindings.a lib/
Final Directory Structure:
[gd-sqlite]
├──godot_fork -> [/path/to/godot/]
├──cpp_bindings/
├──godot_headers/
├──lib/
| └──libgodot_cpp_bindings.a
└──src/
- Compile Library
$ scons
- Copy contents of
gd-sqlite/lib/
intolib/
directory in your godot project. - Open your project in Godot.
- In Godot create GDNativeScript resource:
Create New Resource > GDNativeScript
- Configure Class Name:
GDNativeScript Properties > Class Name
GDSqlite
- Configure library:
GDNativeScript Propeties > Library > New GDNativeLibrary
- Set X11 resource:
GDNativeLibrary Properties > Platform > X11 64bit
res://lib/libgd_sqlite.so
You can now load the GDNativeScript resoure and call library functions from gdscript.
extends Node
# load the GDNativeScript resource
var GDSqlite = load("res://lib/gd_sqlite.gdns");
# instantiate class
var db = GDSqlite.new();
func _ready():
# open database
db.open("test.sql");
# create table
db.create_table("test", ["id INTEGER PRIMARY KEY AUTOINCREMENT", "name TEXT", "test INTEGER"]);
# insert row
db.query("INSERT INTO test (name, test) VALUES ('test', '999');");
# fetch query
var data = db.query_array("SELECT * FROM test;");
print(data.size());
for item in data:
for key in item.keys():
print(item[key]);
# close database
db.close();
pass