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

Luza's Database Api

Started by luza, 20 February 2012 - 08:43 AM
luza #1
Posted 20 February 2012 - 09:43 AM
Luza's Database API


As I haven't found any nice database programs for cc yet I decided to write one myself.
I've not yet finished coding it yet (one function isn't working correct) but I think it'll be released quite soon.

Functions:
  • getVersion()
  • createDatabase(database)
  • dropDatabase(database)
  • selectDb(database)
  • closeDb(database)
  • createTable(table, fields)
  • getTablePath(table)
  • dropTable(table)
  • getFields(table)
  • getField(table, field)
  • getLine(table, index)
  • insert(table, value)
  • select(table, field, like)
Functionexplanations:


getVersion()


Returns the version of the API.

createDatabase(database)


Expects a string. A new database called $database will be created.

dropDatabe(database)


Expects a string. The database $database will be deleted.

selectDb(database)


Expects a string. "opens a connection to the database $database" (not really correct but it's difficult to explain)

closeDb(database)


Expects a string. "closes the connection to the database $database" (again, not really correct)

createTable(table, fields)


Expects a string and a table. Will create a table in the database selected with selectDb() with the fields in $fields.

dropTable(table)


Expects a string. Will delete the table in the database selected with selectDb().

getFields(table)


Expects a string. Will return a table with all the fields in the table $table in the database selected in selectDb().

getField(table, field)


Expects a string and a string. Will return a table with the content of the field $field in table $table in the database selected in selectDb().

getLine(table, index)


Expects a string and a number. Will return a table with the content of the $index-th line of the table $table in the database selected in selectDb().

insert(table, value)


Expects a string and a table. Will insert the content of $value into the table $table in the database selected in selectDb().

select(table, field, like)


Expects a string, table and a table. Will return a two dimensional table containing the fields in witch $field == $like

As it's hard to explain here'S an example:
selectDb("luza")
createTable("testtable",{"field1","field2","field3"}
insert("testtable",{"test","cc","luza"})
insert("testtable",{"test","cc","peter"})

findings = select("testtable",{"field1","field2"},{"test","cc"})

print(findings[1][3])		   --Output:  luza
print(findings[2][3])		   --Output: peter



To Do:
  • release it ;)/>/>
  • add an "update" function
FuzzyPurp #2
Posted 20 February 2012 - 01:51 PM
Looking forward to this..
bastrian #3
Posted 22 February 2012 - 05:48 AM
this would be great to have. For storage systems mayby or even better
luza #4
Posted 22 February 2012 - 05:54 AM
release in probably 2 days
Garthog #5
Posted 05 March 2012 - 01:09 AM
Any news about it ?
Mads #6
Posted 05 March 2012 - 07:07 PM
Does it make online databases?
6677 #7
Posted 06 March 2012 - 01:17 PM
Does it make online databases?
I think they are saved on the computer. Although with some clever trickery you might get it working with rednet or the http api
Migu #8
Posted 24 March 2012 - 03:44 PM
Any ETA on the release? Database api would be really useful.
thatsimplekid #9
Posted 21 December 2012 - 12:29 PM
When will this be released???
Orwell #10
Posted 21 December 2012 - 12:35 PM
When will this be released???
He said exactly 10 months ago that he would release it 2 days after. So my guess is never.