About this project
# godot-sqlite
This GDExtension wrapper makes SQLite3 available in Godot 4.0+ without requiring additional compilation or build script modifications. It supports Mac OS X (universal), Linux, Windows, Android (arm64), iOS (arm64), and HTML5 (stability depends on browser).
## Installation
Install via the Godot Asset Library (search for 'godot-sqlite') or manually download build files from the releases tab. Activate the plugin in Project Settings/Plugins. A demo project is available.
## Usage
### Variables
- **path** (String, default="default"): Path to the database, set before `open_db()`. Supports `res://` and `user://`.
- **error_message** (String): Human-readable error message from the last query.
- **default_extension** (String, default="db"): Auto-appended extension if none given.
- **foreign_keys** (Boolean, default=false): Enable foreign key constraints.
- **read_only** (Boolean, default=false): Open database read-only, allowing packaging in PCK.
- **query_result** (Array): Results from the latest query by value (safe for successive queries).
- **query_result_by_reference** (Array): Results by reference, cleared and repopulated each query.
- **last_insert_rowid** (Integer): Exposes `sqlite3_last_insert_rowid()`.
- **verbosity_level** (Integer, default=1): Console logging level (0=quiet, 1=normal, 2=verbose, 3=very verbose).
### Methods
- **open_db()** / **close_db()**: Open/close a database connection.
- **query(query_string)**: Execute a raw SQL statement.
- **query_with_bindings(query_string, param_bindings)**: Execute with nameless parameter bindings to prevent SQL injection.
- **query_with_named_bindings(query_string, param_bindings)**: Execute with named bindings (supports `:`, `@`, `$`, `?` prefixes).
- **create_table(table_name, table_dictionary)**: Create a table with column definitions (data_type, not_null, unique, default, primary_key, auto_increment, foreign_key).
- **drop_table(table_name)**: Drop a table.
- **insert_row(table_name, row_dictionary)** / **insert_rows(table_name, row_array)**: Insert rows.
- **select_rows(table_name, query_conditions, selected_columns)**: Select rows, returns by value.
- **update_rows(table_name, query_conditions, updated_row_dictionary)**: Update rows.
- **delete_rows(table_name, query_conditions)**: Delete rows.
- **import_from_json(import_path)** / **export_to_json(export_path)**: Import/export database structure and content as JSON.
- **import_from_buffer(input_buffer)** / **export_to_buffer()**: Import/export as JSON-formatted buffer (useful for encryption).
- **create_function(function_name, function_reference, number_of_arguments)**: Bind a scalar SQL function.
- **get_autocommit()**: Check autocommit mode.
- **compileoption_used(option_name)**: Check compile options (e.g., FTS5).
- **backup_to(destination_path)** / **restore_from(source_path)**: Backup/restore database.
- **enable_load_extension(onoff)** / **load_extension(extension_path, extension_entry_point)**: Load SQLite extensions.
- **sanitize_identifier(table_or_column_identifier)**: Sanitize table/column names for safe use in queries.
### Signals
- **row_deleted(table_name, rowid)**: Emitted when a row is deleted.
- **row_inserted(table_name, rowid)**: Emitted when a row is inserted.
- **row_updated(table_name, rowid)**: Emitted when a row is updated.
## FAQ Highlights
- **Syntax errors**: Test queries online, use raw query functions, and ensure proper quoting for strings with spaces or commas.
- **Dynamic table/column names**: Cannot be bound; insert directly into the query string.
- **Mobile/HTML5 access**: Read-only databases must be packaged in PCK; read-write requires copying to `user://`.
- **Server compatibility**: Works with Godot Server binary; older Linux may need recompilation.
- **Extensions**: FTS5, math functions, and R*Tree are supported but require recompilation with flags.
- **Encryption**: Not supported natively; use import/export buffers for custom encryption.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.