Jump to content




Flat Database Engine

api utility computer

  • You cannot reply to this topic
7 replies to this topic

#1 Mirodin

  • Members
  • 33 posts

Posted 12 May 2013 - 05:13 PM

Hello guys,

I made myself a little DB-API for my sorting system with interactive sorter.
My LUA experiences are still very modest so please by patient if some code is quite crappy :)

I hope, someone with some more practice can help me clean it up.

Functions:
  • versioncheck(ver) Checks for the API-Version ver -- Returns true/false
  • check(db) Checks if db is a Database -- Returns true/false
  • erstellen(db, name) Creates name on HD and saves db -- Returns true
  • laden(name) Loads name from HD -- Returns table
  • speichern(db, name) Saves DB db as name on HD -- Returns true
  • suchen(db, item) Searches the DB db for item -- Returns false OR true and i, w (i=key, w= value) OR true and i, k, v(db[k], v=value)
  • anzeigen(db, from, to, mitk) Shows content of DB db from Index from to Index to (from/to optional) -- Returns true (if mitk=true Index gets also returned)
  • einfuegen(db, item, wo, sub, over) Inserts item at Position wo (and "subindex" sub) in DB db. If over is true existing entry gets overwritten -- Returns false OR true and db
  • merge(db1, db2) merges db2 in db1 -- Returns db1
  • loeschen(db, item) Deletes entry item form DB db -- Same as insert
  • backup(name, number) Backups DB name and keeps given number of Backups (number optional)
  • restore(name) Restores DB name
  • drop(name) Drops DB name
  • dropALL(name) Drops DB name and ALL Backups
Spoiler

http://pastebin.com/arDF3wBs

Cheers
Mirodin

P.S.: No warranty for any issues this code produces.
Feel free to modify, improve, whatever. I would appreciate a link and/or credits ;)

Edited by Mirodin, 21 August 2013 - 08:57 AM.


#2 darkrising

  • Members
  • 234 posts
  • LocationScotland

Posted 14 May 2013 - 04:12 AM

Interesting way of storing data, but wouldn't it be easier working with tables?

#3 TorakTu

  • Members
  • 231 posts

Posted 14 May 2013 - 06:28 AM

Dude !! This is brilliant. Great work !

#4 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 14 May 2013 - 08:33 AM

Nice work!

[Offtopic]
Some variables are german :)
I like it to see good german coder :D
I'm german too :P
[/Offtopic]

#5 Mirodin

  • Members
  • 33 posts

Posted 27 May 2013 - 11:23 AM

Sorry for long absence, holidays :D

View PostFreack100, on 14 May 2013 - 08:33 AM, said:

Nice work!

[Offtopic]
Some variables are german :)
I like it to see good german coder :D
I'm german too :P
[/Offtopic]

Thanks man. I know about but was to lazy to replace them all ;)

View Postdarkrising, on 14 May 2013 - 04:12 AM, said:

Interesting way of storing data, but wouldn't it be easier working with tables?

What do you mean? This thing works with tables. There is one Table which contains all the other tables.

#6 computercraftprogrammer

  • Members
  • 122 posts
  • Location$house->Earth->MilkyWay->Universe;

Posted 27 May 2013 - 03:44 PM

Lol this is quite interesting! I am also working on my own MySQL, Except I don't use functions for each command, I am working on complete parsing like SELECT * FROM users WHERE id=1;

#7 btbenedi

  • Members
  • 3 posts

Posted 05 August 2013 - 02:43 PM

Awesome DB API!

I get an error when trying to insert a new item though

db:188: attempt to call nil

That's the db.search(db,item) line in the insert function.

If I call the db.search(db,item) with the item I'm trying to input, it returns false, as it should since it's a new item. Any ideas?

All of the other functions work flawlessy, I love the backup function.

EDIT: Seems like it's because it's db.search, trying to call it as if it's loaded within itself. Changed db.search to search and it seems to work now.

#8 Mirodin

  • Members
  • 33 posts

Posted 05 August 2013 - 03:44 PM

View Postbtbenedi, on 05 August 2013 - 02:43 PM, said:

Awesome DB API!

I get an error when trying to insert a new item though

db:188: attempt to call nil

That's the db.search(db,item) line in the insert function.

If I call the db.search(db,item) with the item I'm trying to input, it returns false, as it should since it's a new item. Any ideas?

All of the other functions work flawlessy, I love the backup function.

EDIT: Seems like it's because it's db.search, trying to call it as if it's loaded within itself. Changed db.search to search and it seems to work now.

Thank you for feedback. I fixed this issue quite some time ago but forgot to uploade it again :rolleyes:
I did quite a bunch of changes the last time and at the moment I think I will pubish that the next days.

Cheers





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users