Godot: Integrate sqlite into godot 3.0

Created on 6 Apr 2017  路  5Comments  路  Source: godotengine/godot

I wonder if you can integrate this sqlite module by khairul169 into godot 3.0?
Could be useful in many cases

discussion feature proposal plugin

Most helpful comment

I think this is better suited to be a DLScript wrapper. I don't really see a reason to have it in the engine as I think it's more game specific than general purpose.

With a DLScript it could look like this

extends Node

# this is what it would look like with the module
# var db = SQLite.new();

# this is what it would look like with a DLScript
var db = preload("res://SQLite/SQLite.dl")

func _ready():
    # Open SQL
    if db.open("user://data.sql") != db.SQLITE_OK:
        print("ERR: ", db.get_errormsg());
        return;

    # Create database if not exists
    db.query("CREATE TABLE IF NOT EXISTS players (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, email TEXT, playcount INTEGER);");

    # Select Operation
    for i in db.fetch_array("SELECT * FROM players LIMIT 100;"):
        print(i);

        # Update Operation
        db.query("UPDATE players SET playcount='"+str(i["playcount"]+1)+"' WHERE id='"+str(i["id"])+"';");

    # Insert Operation
    db.query("INSERT INTO players (name, email, playcount) VALUES ('khairul', '[email protected]', '0');");

    # Remove Operation
    db.query("DELETE FROM players WHERE playcount > '5';");

    db.close();

(so you can see, it would look just like the module code, you only create an instance differently and it doesn't need to be part of the engine)

All 5 comments

I think this is better suited to be a DLScript wrapper. I don't really see a reason to have it in the engine as I think it's more game specific than general purpose.

With a DLScript it could look like this

extends Node

# this is what it would look like with the module
# var db = SQLite.new();

# this is what it would look like with a DLScript
var db = preload("res://SQLite/SQLite.dl")

func _ready():
    # Open SQL
    if db.open("user://data.sql") != db.SQLITE_OK:
        print("ERR: ", db.get_errormsg());
        return;

    # Create database if not exists
    db.query("CREATE TABLE IF NOT EXISTS players (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, email TEXT, playcount INTEGER);");

    # Select Operation
    for i in db.fetch_array("SELECT * FROM players LIMIT 100;"):
        print(i);

        # Update Operation
        db.query("UPDATE players SET playcount='"+str(i["playcount"]+1)+"' WHERE id='"+str(i["id"])+"';");

    # Insert Operation
    db.query("INSERT INTO players (name, email, playcount) VALUES ('khairul', '[email protected]', '0');");

    # Remove Operation
    db.query("DELETE FROM players WHERE playcount > '5';");

    db.close();

(so you can see, it would look just like the module code, you only create an instance differently and it doesn't need to be part of the engine)

A GDNative version has been released by @khairul169 for those interested.

https://github.com/khairul169/gdsqlite-native

Thanks for the link, a GDNative module is definitely the way to go. Closing this issue as there is no plan to integrate it directly into the main engine.

@akien-mga I'd just like to chime in here, on this closed issue, to suggest that SQLite support be an official part of Godot, even if it is kept as a separate and optional plugin. There are a variety of issues getting it to work in 3.0.6, at the moment, including the fact that the database location is limited, etc.

SQLite is the most widely deployed database library in the world, in use on every single Android and iOS device, as well as MacOS and probably Windows (though I'm not sure there). When dealing with larger reference datasets, JSON adds a lot of bloat and it is not feasible to load huge JSON reference files into memory. SQLite is the answer to that.

I understand why you don't consider it a core feature. I do, however, believe that you should revisit it as an officially adopted and supported plugin.

Code in open source projects is usually maintained by whoever uses it. It does not really make a difference whether it is official or not, as this will not make developers who are not interested on it to do so. If there is no interest, it will be neglected anyway.

That said, eventually, we can host it in our Github organization in case more contributors want to contribute to it.

Was this page helpful?
0 / 5 - 0 ratings