How to connect to a database?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Zera
:warning: Old Version Published before Godot 3 was released.

I’m starting development of a multiplayer turn based strategy game and need a way to store information about the players, their units, stats and other information so that they aren’t lost as soon as the server is closed. A database would be ideal for this but so far I haven’t been able to find any information on how to connect to a database from within Godot. This could be useful for other types of games like RPGs, I think, and would allow for easy tuning of game balance if developed correctly.

TL;DR, how can I connect to a database from within the game engine?

:bust_in_silhouette: Reply From: Mohammad Hadi Aliakb

a database is not supported wirte now but I think a module for sqlite can be written, you can use dictionaries for most of things that you said.
but if you need a sqlite or something like that you can write a module for it or just open an issue for feature request in github.

I thought about using dictionaries, too, but the problem would then be how to persist those dictionaries (in case of server crash or anything like that). I guess the best option will be to write a C++ module to connect to a PostgreSQL database, then.

Zera | 2016-02-26 19:55

:bust_in_silhouette: Reply From: dragoon

Try this SQLite3 plugin: GitHub - khairul169/gdsqlite: SQLite wrapper for Godot Engine.

the repository has not been updated since 2017!

frankiezafe | 2019-05-29 15:45

:bust_in_silhouette: Reply From: frankiezafe

The actual best candidate is GitHub - khairul169/gdsqlite-native: SQLite module for Godot 3.x referenced as the 3.x version of this module in the original repository.

You may wanna remove the comma at the end of the link. It’s not working right now.

Dlean Jeans | 2019-05-30 12:30

it took me 15 sec’ before getting where the error was :slight_smile:

frankiezafe | 2019-05-30 12:34

:bust_in_silhouette: Reply From: Samuel Marzin

If you want to develop a massively multiplayer game, you absolutely should not use sqlite which has write, space and scale limits. Prefer a database on the network like mysql or postgresql. I recommend postgres. Here is a postgres godot connector: GitHub - Marzin-bot/PostgreSQLClient: PostgreSQL connector for Godot Engine in GDScript.