Introducing rSQL: SQL-Like Operations for Roblox Datastores and Profiles

no, i meant like a search function instead of looking for an identical match

if i had a table that was formated like this:

name | id | author_id | contents 
Bunker | 0 | 0 | GENERIC_JSON_DATA_HERE
House | 1 | 0 | GENERIC_JSON_DATA_HERE
Manor | 2 | 1 | GENERIC_JSON_DATA_HERE
Bank | 3 | 2 | GENERIC_JSON_DATA_HERE
Rustacean Beach | 4 | 2 | GENERIC_JSON_DATA_HERE

and I queried the name with the string/letter “U”, it should return rows with the id #0, #1, and #4, since all of the mentioned names have the letter U in them

1 Like

I would do it like this:

local DataStoreService = game:GetService("DataStoreService")
local rSQL = require(game.ReplicatedStorage.Packages.rSQL)

local config = {
	allowCreate = true,
	allowInsert = true,
	allowSelect = true,
}

local datastore = DataStoreService:GetDataStore("SearchExampleDatabase" .. os.time())
local connection = rSQL:connect(datastore, config):expect()

local function searchWithSubstring(connection, tableName, searchString)
	local queryResult = connection:query(string.format("SELECT * FROM %s", tableName)):expect()
	print(queryResult)
	-- ur logic here but data looks like this:
	-- ▼  {
	--	[1] =  ▼  {
	--		["author_id"] = "0",
	--		["contents"] = "GENERIC_JSON_DATA_HERE",
	--		["id"] = "0",
	--		["name"] = "Bunker"
	--	},
	--	[2] =  ▼  {
	--		["author_id"] = "0",
	--		["contents"] = "GENERIC_JSON_DATA_HERE",
	--		["id"] = "1",
	--		["name"] = "House"
	--	},
	--	[3] =  ▼  {
	--		["author_id"] = "2",
	--		["contents"] = "GENERIC_JSON_DATA_HERE",
	--		["id"] = "4",
	--		["name"] = "Rustacean"
	--	}
	--} 
end

connection:query("CREATE TABLE Locations (name, id, author_id, contents)"):expect()
connection:query("INSERT INTO Locations (name, id, author_id, contents) VALUES ('Bunker', 0, 0, 'GENERIC_JSON_DATA_HERE')"):expect()
connection:query("INSERT INTO Locations (name, id, author_id, contents) VALUES ('House', 1, 0, 'GENERIC_JSON_DATA_HERE')"):expect()
connection:query("INSERT INTO Locations (name, id, author_id, contents) VALUES ('Rustacean', 4, 2, 'GENERIC_JSON_DATA_HERE')"):expect()

local results = searchWithSubstring(connection, "Locations", "U")
print("Search Results:")
for _, row in ipairs(results) do
	print(row)
end

By the way it seems you made me find a bug in the YACC.luau and ACT Tree which prevents rows from having spaces, will release a patch ASAP.

1 Like

Released a patch, rSQL now accepts spaces in strings.

Added LIKE operator support in SELECT