Skip to content

maxmurder/gd-sqlite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gd-sqlite

A GDNative SQLite wrapper module for Godot 3.0

Compiling

  1. Compile Godot 3.0
  2. 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
  1. Link godot source
$ ln -s [/path/to/godot/] godot_fork
[gd-sqlite]
    ├──godot_fork -> [/path/to/godot/]
    ├──cpp_bindings/
    ├──godot_headers/
    └──src/
    
  1. Generate bindings:
$ cd cpp_bindings
$ scons godotbinpath="../godot_fork/bin/" headers="../godot_headers/" p=linux generate_bindings=yes
  1. 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/
  1. Compile Library
$ scons

Import GDNative library

  1. Copy contents of gd-sqlite/lib/ into lib/ directory in your godot project.
  2. Open your project in Godot.
  3. In Godot create GDNativeScript resource: Create New Resource > GDNativeScript
  4. Configure Class Name: GDNativeScript Properties > Class Name GDSqlite
  5. Configure library: GDNativeScript Propeties > Library > New GDNativeLibrary
  6. Set X11 resource: GDNativeLibrary Properties > Platform > X11 64bit res://lib/libgd_sqlite.so

Usage

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

About

sqlite GDNative wrapper module for Godot 3.0

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages