This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Awsomehawk's profile picture

Database

Started by Awsomehawk, 25 July 2012 - 05:26 PM
Awsomehawk #1
Posted 25 July 2012 - 07:26 PM
Im Currently making a huge project. I need help I want you type every single thing you know about how to create a database.
Im also looking for help on this project. the more you help me on the forums and the more i need you to physically help me with this
Cranium #2
Posted 25 July 2012 - 08:21 PM
Pretty sure that if you haven't done any of the legwork yourself, then not too many Pros would be willing to code that for you. Start working out some of the code yourself, post it here, and I think they'll be willing to help.
Awsomehawk #3
Posted 25 July 2012 - 08:53 PM
Pretty sure that if you haven't done any of the legwork yourself, then not too many Pros would be willing to code that for you. Start working out some of the code yourself, post it here, and I think they'll be willing to help.
I already have started working on it and im not asking for them to write it for me im asking how i can write it tips trick every thing about doing this i need as much knowledge i can get this project i can get i got a good chunk of it done already the size of it is huge i need all i can get
Lyqyd #4
Posted 26 July 2012 - 02:41 AM
http://www.lua.org/manual/5.1/
http://computercraft.info/wiki/index.php?title=Category:APIs

There ya go.
Cranium #5
Posted 26 July 2012 - 03:53 AM
BWAHAHAHA!!!!!!!
That is everything there is to know about making a database. Better get to it, Awsomehawk, that's not really light reading!
KingMachine #6
Posted 26 July 2012 - 06:22 AM
Being pro;
these two clowns are doing it wrong.

In order to figure out what you need to do you need to ask yourself "why?"
in this case the "why" is to have an organized list of information.
the "what" is that you are storing it in an indexable format.
how is going to be the tricky part.
You need to visualize the indices (plural index) and imagine how you are going to be able to use your database.
You want to access particular sections. How will they be named? I would do it in XYZ
X being topic
Y being age number
Z being the information

That's just me. I have a chronological memory.

This is about all that I can share on the subject as I've never actually coded a database. I can't imagine it being very enjoyable..but I think I might make one to store information on players and their offenses or accomplishments on my server ;]. That would allow me to actually allow people to inherit my server later on without me needing to tell them everything about everyone. I'm ranting. Good luck.

EDIT:
And by the way, if you are still looking for tips and tricks but you've written a lot of it; expect to have to rewrite it when you have an epiphany.
tfoote #7
Posted 26 July 2012 - 06:32 AM
design it like a wearhouse. in a wearhouse each piece has an ID. then using this ID you can get all the info. Its basically just using tables!

Edit: Im working on something similar. Happy Coding
KaoS #8
Posted 26 July 2012 - 09:31 AM
what I would advise is making a table so

local db={}

then you use variables to name subdivisions of the table so for example if you were documenting players:


term.clear()
term.setCursorPos(1,1)
write("LOGIN:nUsername: ")
local name=read()
if db[name]==nil or type(db[name])~="table" then
db[name]={}
end
if db[name]["password"]==nil then
term.clear()
term.setCursorPos(1,1)
print("Welcome new user!nEnter your new password: ")
password=read('*')
db[name]["password"]=password
end
db[name]["last_login_at"]=os.getComputerID()

etc. point is you use a table and then use variables to navigate it, you can have multiple terminals and set them to send all input to a server and they can request data etc, it gets fairly complicated when you make everything remote but yeah… pm me if you need any more specific examples
KaoS #9
Posted 26 July 2012 - 09:33 AM
you would also have to add an else statement to that if statement about the password because if a password is defined the user has to enter it
Lyqyd #10
Posted 26 July 2012 - 03:02 PM
Being pro;
these two clowns are doing it wrong.

Neither "clown" nor "doing it wrong" are applicable. The effort I'm willing to put in is directly dependent on the effort OP is willing to put in. Extraordinarily broad questions should get extraordinarily broad answers.
KingMachine #11
Posted 27 July 2012 - 05:23 AM
Being pro;
these two clowns are doing it wrong.

Neither "clown" nor "doing it wrong" are applicable. The effort I'm willing to put in is directly dependent on the effort OP is willing to put in. Extraordinarily broad questions should get extraordinarily broad answers.

I can agree with that. I retract my statement.
Jarle212 #12
Posted 05 November 2012 - 03:02 AM
I think using block of data to store the information about each user could work. Ant the use gsub to check for blocks

["USER1"]{
ID: 1
NAME: "USER1"
AGE: …
etc
}
Doyle3694 #13
Posted 05 November 2012 - 06:45 AM
Jarle, recoding tables is not nessesary.

users = {
[John] = {ID = 1, Age = 23, --Space for additional stuff--}
[Steve] = {ID = 2, Age = 14, --Space for additional stuff--}
[Vanessa] = {ID = 3, Age = 17, --Space for additional stuff--}
}
Sammich Lord #14
Posted 05 November 2012 - 11:41 AM
This is how I do it for my mouse GUI:


buttons = {
  [1] = {
    visible = true,
    text = hi,
    command = hello
  }
}

That is the basics of it.
PaxNova #15
Posted 22 December 2012 - 02:21 PM
Making the database system isn't the hard part. You need to look into how current database systems work, e.g. MyISAM and InnoDB.
One difference between the two that I can think of I think you want to carry over or test out in your CC setup - row locking.

Now to start with, all data should be kept in tables. By keeping variables defined as their authentic types in Lua, you do not need to worry about converting any back and forth between your application and the storage.
In addition this allows you to very easily store them to the file system without having to design a format of your own. You can just serialize the tables using textutils.serialize(), and unserialize them when you load them back up. It provides minimal system load and again you're not taking unnecessary steps that could damage your data's integrity.

However databases can get very large, and there are two approaches I can envision that would resemble the two DBS' just mentioned:

- Loading the stored data upon startup, keeping all of it in active memory, processing queries with the data from memory and writing it to the disk periodically/on shutdown.
This would more resemble MyISAM, as it would involve a form of table locking versus row locking in the example I'll give you next. I can see definite merit in lowering the quantity of (CPU intensive) read/write operations to the disk, but as the tables fill up they'll start hogging the server's memory. It depends on how much data you want to store.

- Indexing all databases as seperate folders, and within them all data tables. Within the table folders store serialized Lua tables that represent each individual row
This would lean more towards InnoDB in terms of only opening up required rows. If lots of write operations occur it may be heavy on the server, but at the same time the principle of row locking involves writing each data table row separately as this means multiple rows can be affected simultaniously without conflicts.
In addition, seeing as how we're talking about CC computers, you would spare the server's RAM by not keeping all of the data in active memory constantly, and indexing would still be a sinch since you can simply save the serialized rows to files named after their ID number.

Just some musings. However, the hard part will be making a query language.
ChunLing #16
Posted 22 December 2012 - 05:36 PM
What is with the sudden necromancy?
PaxNova #17
Posted 23 December 2012 - 01:20 AM
The subject drew my attention since I've been thinking about it myself and I decided to share my thoughts. Maybe it'll help someone. Maybe I'll get some input on which of the two approaches I listed would be preferable.
ChunLing #18
Posted 23 December 2012 - 02:04 AM
Well, both approaches have merits, and liabilities. But which would be preferable depends on the specifics of your intended use. I'd have to guess the first, for most cases I can readily imagine being useful in-game, but my idea of what is useful in-game is really pretty limited compared to what some people seem to think is useful in-game.
PaxNova #19
Posted 23 December 2012 - 07:34 AM
Well there are definite uses. Outside of regular database applications (Storing item information and whatnot) it would allow for programming with a decent, peristent ORM. Considering Lua's ability to mimick OOP behavior with tables, I can see MVC architecture working out quite nicely for more advanced, extensible systems (e.g., in-game forums, mailservers)
corisco1917 #20
Posted 28 January 2013 - 06:47 AM
i guess the easiest database to implement in computercraft is nosql database like http://docs.mongodb.org/manual/

if u don't know how mongo works, this article - http://horicky.blogs...chitecture.html - should help you understand…

i am working on simplified for computercraft noSQL database api to store simple informations about turtle, computers and chests(like its position, number of slots avaible and how many items in each slots etc…)