How do you get type information from GDNative addons?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By shackra

I will use godot-sqlite since I want database capabilities in my game, but I notice that there is no type information from the add-on:

extends Node

const SQLite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns")
var db = SQLite.open_db("")

Somehow db shows auto-completion suggestions in Godot 3.4 that don’t mean anything to me or seems related to this add-on. Do you have any idea how to get typing information for godot-sqlite?

:bust_in_silhouette: Reply From: shackra

Silly me, you need to use SQLite.new() and then you can interact with your database.

extends Node
const SQLite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns")
const OSes = ["Android", "iOS", "HTML5"]
var db_name := "user://db/game" if OS.get_name() in OSes else "res://db/game"
var _db := SQLite.new()

func copy_data_to_user() -> void:
	var data_path := "res://db"
	var dest_path := "user://db"
	var dir = Directory.new()
	dir.make_dir(dest_path)
	if dir.open(data_path) == OK:
		dir.list_dir_begin();
		var file_name = dir.get_next()
		while (file_name != ""):
			if dir.current_is_dir():
				pass
			else:
				cprint("Copying " + file_name + " to /user-folder")
				dir.copy(data_path + "/" + file_name, dest_path + "/" + file_name)
			file_name = dir.get_next()
	else:
		cprint("An error occurred when trying to access the path.")

func get_current_user_version() -> int:
	_db.query("PRAGMA user_version;")
	assert(len(_db.query_result) > 0, "cannot get user_version from database")
	return int(_db.query_result[0]["user_version"])

func _ready():
	if OS.get_name() in OSes:
		copy_data_to_user()

	_db.path = db_name
	_db.verbose_mode = true
	_db.open_db()
    get_current_user_version()