2shady4u / godot-sqlite

GDExtension wrapper for SQLite (Godot 4.x+)
MIT License
947 stars 82 forks source link

database.db isnt in game file #89

Closed Melon-The-Dev closed 2 years ago

Melon-The-Dev commented 2 years ago

Environment:

Steps to reproduce: exporting the project

Minimal reproduction project:

Additional context

2shady4u commented 2 years ago

Hello @MehLoon,

The answer to your question depends on if you are working with a read-only or with a read-write database. Here are the relevant sections from the documentation:

Read-only databases

If your database serves as static data storage i.e. there's no persistent dynamic data that needs to be saved, then your database is a read-only database. For example, a database that contains a table of monster descriptions and data (experience gained on kill, health points) probably never changes during normal gameplay.

In this case, the database can be packaged in the *.pck-file together with all other assets without any hassle.
To enable this behaviour following conditions need to be met:

  • The database file has to be added manually to the include_filter of your export_presets.cfg-file to package the file on export.
  • The connection has to be opened in read-only mode by setting the read_only variable to True.

You can also open databases in read-only mode that are not packaged, albeit under some restrictions such as the fact that the database files have to copied manually to user://-folder on mobile platforms (Android & iOS) and for web builds.

One important additional constraint for read-only databases is that Godot's implementation of file handling does not allow files to opened in a shareable manner. Basically this means that opening a database connection fails whenever other programs have a read lock on the database file e.g. having the file open in SQLiteStudio for editing purposes. However, multiple simultaneous read-only database connections are allowed.

NOTE: The contents of your PCK file can be verified by using externally available tools as found here.

Read and write databases

NOTE: On mobile platforms (Android & iOS) and for web builds, the method discussed here is not possible and the contents of the res://data/-folder have to be copied to the user://-folder in its entirety instead (see FAQ above).

If your database serves as dynamic data storage i.e. there's persistent dynamic data that needs to be saved during gameplay, then your database is a read and write database. For example, a database that contains a table of character levels and experience dynamically changes whenever the player levels up and/or gains experience.

In this case, the database cannot be packaged in the *.pck-file as the contents of this file are static and cannot be dynamically modified during normal operation.

All *.db-files (and *.json-files if you choose not to include them in the *.pck) should preferably be part of the same folder. For example, in the case of the demo-project this is the data/-folder. During export this folder has to be copied in its entirety and placed alongside the executable that is created by Godot's export command line utilities.

Hopefully this helps?

2shady4u commented 2 years ago

Hello @MehLoon,

Is there any update on this issue?

2shady4u commented 2 years ago

Closed #89 due to inactivity