mirror of
https://github.com/RPG-Research/bcirpg.git
synced 2024-04-16 14:23:01 +00:00
created quite a few query functions to create a better CRUD usecase for the Genre selection function
This commit is contained in:
parent
50898e60b6
commit
bcf8a84f2b
@ -7,14 +7,11 @@ const SQLite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns")
|
|||||||
var db
|
var db
|
||||||
var db_name = "res://databases/genre_sub"
|
var db_name = "res://databases/genre_sub"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# An item will contain the ID of the item in question, followed by the genre name, and the alias provided.
|
# An item will contain the ID of the item in question, followed by the genre name, and the alias provided.
|
||||||
# Examples of how to use createItem
|
# Examples of how to use createItem
|
||||||
# createItem("Melee-Weapon")
|
# createItem("Melee-Weapon")
|
||||||
# createCollection("Dessert Ration Item")
|
# createItem("Dessert Ration Item")
|
||||||
# createCollection("Single Rider Vehicle")
|
# createItem("Single Rider Vehicle")
|
||||||
|
|
||||||
func createItem(inputNameString):
|
func createItem(inputNameString):
|
||||||
db.open_db()
|
db.open_db()
|
||||||
var tableName = "Item"
|
var tableName = "Item"
|
||||||
@ -29,7 +26,6 @@ func createItem(inputNameString):
|
|||||||
# createCollection(3, "SciFi", "Plasma Pistol")
|
# createCollection(3, "SciFi", "Plasma Pistol")
|
||||||
# createCollection(3, "ModernDay", "9MM Handgun")
|
# createCollection(3, "ModernDay", "9MM Handgun")
|
||||||
# createCollection(3, "Fantasy", "Shortbow")
|
# createCollection(3, "Fantasy", "Shortbow")
|
||||||
|
|
||||||
func createCollection(ItemID, collectionName, aliasName):
|
func createCollection(ItemID, collectionName, aliasName):
|
||||||
db.open_db()
|
db.open_db()
|
||||||
var tableName = "Collection"
|
var tableName = "Collection"
|
||||||
@ -41,36 +37,72 @@ func createCollection(ItemID, collectionName, aliasName):
|
|||||||
print(dict)
|
print(dict)
|
||||||
|
|
||||||
|
|
||||||
|
# This will r all records under a genreName.
|
||||||
|
# Examples of how to use
|
||||||
|
# readCollectionByGenreName("SciFi")
|
||||||
|
# readCollectionByGenreName("ModernDay")
|
||||||
|
# readCollectionByGenreName("Fantasy")
|
||||||
|
func readCollectionByGenreName(feedName):
|
||||||
|
db.open_db()
|
||||||
|
var tableName = "Collection"
|
||||||
|
db.query("select * from " + tableName + " where genreName = \"" + str(feedName) + "\"")
|
||||||
|
for i in range(0, db.query_result.size()):
|
||||||
|
print("TEST")
|
||||||
|
print("Query results ", db.query_result[i]["itemAlias"], db.query_result[i]["primaryKey"])
|
||||||
|
return db.query_result
|
||||||
|
|
||||||
|
|
||||||
#Not to sure about this one. We may need to talk about a refactor here
|
#Not to sure about this one. We may need to talk about a refactor here
|
||||||
func createGenreSubstitutionLayer(collectionID):
|
#func createGenreSubstitutionLayer(collectionID):
|
||||||
db.open_db()
|
# db.open_db()
|
||||||
var tableName = "Genre_Substitution_Layer"
|
# var tableName = "Genre_Substitution_Layer"
|
||||||
var dict : Dictionary = Dictionary()
|
# var dict : Dictionary = Dictionary()
|
||||||
dict["collectionID"] = collectionID
|
# dict["collectionID"] = collectionID
|
||||||
db.insert_row(tableName,dict)
|
# db.insert_row(tableName,dict)
|
||||||
print(dict)
|
# print(dict)
|
||||||
|
#
|
||||||
|
|
||||||
|
func readItemsByID(id):
|
||||||
func getItemsByID(id):
|
|
||||||
db.open_db()
|
db.open_db()
|
||||||
db.query("select Item.baseName as baseName, Collection.collectionName as genreName from Item left join Collection on Item.primaryKey = Collection.itemID where Item.primaryKey = " + str(id))
|
db.query("select Item.baseName as baseName, Collection.collectionName as genreName from Item left join Collection on Item.primaryKey = Collection.itemID where Item.primaryKey = " + str(id))
|
||||||
for i in range(0, db.query_result.size()):
|
for i in range(0, db.query_result.size()):
|
||||||
print("Query results ", db.query_result[i]["baseName"], db.query_result[i]["genreName"])
|
print("Query results ", db.query_result[i]["baseName"], db.query_result[i]["genreName"])
|
||||||
return db.query_result
|
return db.query_result
|
||||||
|
|
||||||
|
# This will delete an Item record under your desired ID.
|
||||||
# TO DO: Modify this query to provide a list of all items, that use the refer to the same base item; using item.baseName as the query item
|
# Examples of how to use deleteItemByID
|
||||||
|
# deleteItemByID(2)
|
||||||
#func getItemsByBaseName(feedName):
|
func deleteItemByID(id):
|
||||||
# db.open_db()
|
db.open_db()
|
||||||
# db.query("select Item.baseName as baseName, Collection.collectionName as genreName from Item left join Collection on Item.primaryKey = Collection.itemID where Item.primaryKey = " + str(feedName))
|
var tableName = "Item"
|
||||||
# for i in range(0, db.query_result.size()):
|
db.query("delete from " + tableName + " where primaryKey = " + str(id))
|
||||||
# print("Query results ", db.query_result[i]["baseName"], db.query_result[i]["genreName"])
|
print("Deleted Item by ID " + str(id) + ".")
|
||||||
# return db.query_result
|
|
||||||
|
|
||||||
|
|
||||||
func readItem():
|
# This will delete a Collection record under your desired ID.
|
||||||
|
# Examples of how to use deleteCollectionByID
|
||||||
|
# deleteCollectionByID(2)
|
||||||
|
func deleteCollectionByID(id):
|
||||||
|
db.open_db()
|
||||||
|
var tableName = "Collection"
|
||||||
|
db.query("delete from " + tableName + " where primaryKey = " + str(id))
|
||||||
|
print("Deleted Collection by ID " + str(id) + ".")
|
||||||
|
|
||||||
|
# This will read an Item record under your desired baseName.
|
||||||
|
# Examples of how to use readItemByBaseName
|
||||||
|
# readItemByBaseName("sword")
|
||||||
|
func readIDByBaseName(feedName):
|
||||||
|
db.open_db()
|
||||||
|
var tableName = "Item"
|
||||||
|
db.query("select primaryKey as itemIDKey from " + tableName + " where baseName = \"" + str(feedName) + "\"");
|
||||||
|
for i in range(0, db.query_result.size()):
|
||||||
|
print("ID = ", db.query_result[i]["itemIDKey"])
|
||||||
|
return db.query_result
|
||||||
|
|
||||||
|
|
||||||
|
#This will read all items in the entire database.
|
||||||
|
#Just call this function to return them.
|
||||||
|
func readItems():
|
||||||
db.open_db()
|
db.open_db()
|
||||||
var tableName = "Item"
|
var tableName = "Item"
|
||||||
db.query("select * from " + tableName)
|
db.query("select * from " + tableName)
|
||||||
@ -81,10 +113,4 @@ func readItem():
|
|||||||
func _ready():
|
func _ready():
|
||||||
db = SQLite.new()
|
db = SQLite.new()
|
||||||
db.path = db_name
|
db.path = db_name
|
||||||
getItemsByID(3)
|
|
||||||
pass # Replace with function body.
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
#func _process(delta):
|
|
||||||
# pass
|
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user