Databases: File or SQL?

Hi everyone. I have some sort of loadout system, where player decides himself what weapons should be given him on spawn. I have a weapon table like


soc.weps = {
	[101] = {
		class = "weapon_fists",
		name = "Hands",
		price = 0,
		model = "models/weapons/w_hands.mdl",
	},
	[102] = {
		class = "weapon_physgun",
		name = "Physgun",
		price = 0,
		model = "models/weapons/w_superphyscannon.mdl",
	},
	[103] = {
		class = "gmod_camera",
		name = "Camera",
		price = 0,
		model = "models/maxofs2d/camera.mdl",
...

so each player has a table representing his loadout


ply.soc_loadout = {101, 102, 103}

So here is the question - is it okay to use file based database in that case? Is it good to system to store about 8,000 (approximated amount of unique players joined to server over last 6 months) files 1Kb each? Or probably I should create a SQL table with 2 columns (SteamID, JSON with loadout)?

What seems simpler to you? 8,000 text files or 2 columns?

Also, from the wiki page:

[editline]13th August 2017[/editline]

I voted ‘files are best for that purpose’ by accident sorry

Or you could…you know… make it under one table in one text file if you don’t know SQL…

Wouldn’t even be in the data files so you wouldn’t even have to network it from there. From what I see, it would just be a static table. A configuration file of sorts.

Wouldn’t have to rely on SQL.

I actually already use SQL in other cases so it’s not a problem at all. But I dislike the idea to load 8k entries at once, especially when only 10-20 will be used on runtime. Waste of RAM, even if there will be no impact on performance.

me personally I know only a little on SQL but I do prefer to use it before anything else. any addon I have for my server I always make sure to use the SQL option if available.

The only reason I would is so you don’t have to rely on the SQL server. Less factors.

What do you mean by SQL server? All the data is stored in local sv.db

It’s up to you. SQL will be better in most (if not all) cases. Saving data in text files should only really be used if the data inside of the file isn’t too large and the process relating to the text files is simple and doesn’t happen too often (although an actual DB will prove to be better in every aspect basically).

Text files are good if you just want to make something fast so you don’t have to setup an actual db + write the queries but just make sure you’re not trying to read a crazy amount of data often.

If you have ever touched SQL I would definitely check that out, it’s a very useful when it comes to storing and retrieving data. Gmod uses SQLite to store data locally in sv.db but you can use modules that utilize SQL such as mysqloo and tmysql

:confused:

I wouldn’t know. I never bothered learning SQL. But aren’t SQL databases stored in MySql databases online? Hence like the donation systems and such?

sv.db and cl.db are gmods SQLite built in functionality, you can have you server connect to a sql server online if you choose but by default they use the local SQLite dbs… also, someone just told me a bit ago the sql data tends to corrupt a lot, is that not the case?

SQL database is just a file type, like “example.db”, you can access it anytime, it is located in garrysmod folder and named cl.db or sv.db. I’m sure there is a way to connect it with other databases, but I have no idea how :smiley:

And I thought that all the donation info synchs between gmod server and website host using http protocols, and both sides do have SQL databases (files). At least that’s how I see it :stuck_out_tongue:

Using files for anything except loading them one time or something is bad due to gmod stopping everything while reading or writing files. If you are making a file for every player then you are murdering the server.

Can anyone confirm gmod actually stops everything while reading and writing files?

Why are we even debating this in the first place? Databases trump files for this kind of thing in any way you try to spin it. Databases were specifically designed to prevent this from happening, and to enable people to do more with the data than a file could.

You coming up with reasons why using a file I/O system is better than a database is just plain uninformed and silly.

If you want a solid answer, here it is:

If you have just one server, and you have no intentions on adding another, or having a website interact with anything on your game server, then you can use the SQLite implementation in GMod.

Player:SetPData

Player:GetPData
etc.

If you want to integrate another server in the future, or a website, then you will need to use MySQL. To do that, you will need a MySQL module, and for that, I recommend MySQLOO: http://forum.facepunch.com/showthread.php?t=1515853

Files are not an option for 99.99% of anything you would want to do in this scenario.

I’m not debating, I’m asking this because I need to know. Stop mumbling and jumbling my words. If this is actually true, then I have a whole lot of work to do.

[editline]13th August 2017[/editline]

What about in the scenario of me writing and getting data files based on the Steam64ID of a player for my own custom addon? As in, I would be writing and reading the files about 10-20 times per minute (maybe that’s a low, if it’s a 100 player server, then a lot more.)

Dude. I literally do not know how else to explain this to you. There is no situation that you could imagine that files would outperform a database. At all, ever, period.

No one sat down at the MySQL conference table and said, “Hey, let’s design a system worse than storing data in a file!”.

I’m not asking you what “outpreforms”. I’m asking if the server actually stops while doing data gets and writes.

Also, what is it with you and MySql, are you two like dating?

to put it simple, think of it as 2 separate computers. 1 runs your server, the other one runs database related things. would you rather have 1 CPU for databases+server or 2 CPUs split to where DATABASE and SERVER have their own individual CPUs? there is also to mention that sql looks a lot nicer and is much easier to manage since you kinda have a spreadsheet look to it. faster, cleaner, better for the players

*Snip, not even worth the comment.

side note, other then SQL or File is there even a third option that exists? kinda curious at this point if there is