Search Unity

iBoxDB -Lightweight Embedded Database

Discussion in 'Assets and Asset Store' started by Bruce3D, Dec 13, 2013.

  1. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    501
    @Bruce3D Thank you for your detailed answers!

    Actually the field is just a string. What I'm doing now is:

    Code (CSharp):
    1.  
    2. List<string> tags = new List<string>(new string[] { "tag1", "tag2", "tag3" });
    3.  
    4. List<PhotoData> results = auto.Select<PhotoData>("from PhotoData where DateTaken > ? & DateTaken < ?", fromDate, toDate).Where(o => tags.Contains(o.Tags)).Skip(offset).Take(numItems).ToList();
    5.  
    I'm still a bit unclear about what EnsureIndex does - does it index the field to make searches faster? So does this only need to be done once when the DB is setup?

    Thanks
     
  2. Bruce3D

    Bruce3D

    Joined:
    Sep 6, 2013
    Posts:
    56
    Some books have an Index at the end, it helps readers find content efficiently.
    if want to find Term faster, create a Term index
    EnsureIndex( ... "Term");
    Select( ".. where Term==?");

    if want to find [Title->Term] faster, create a [Title->Term] index. the order of fields matters.
    EnsureIndex( ... "Title", "Term");
    Select( ".. where Title==? & Term==?");

    small book doesn't have Index, it is not necessary, when data reached 1,000,000. it helps.

    Index accelerates Search, decelerates Update.

    http://www.iboxdb.com/
     
    Last edited: Aug 30, 2017
    iddqd likes this.
  3. friuns3

    friuns3

    Joined:
    Oct 30, 2009
    Posts:
    307
    wow suprised it works on webgl! where it stores data there? and is there any limitations?
     
  4. Bruce3D

    Bruce3D

    Joined:
    Sep 6, 2013
    Posts:
    56
  5. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Is there a documentation? This library looks promising and just like what i'm looking for, but i find it hard to figure out what certain classes/methods exactly do so i know how to use them.
     
  6. Bruce3D

    Bruce3D

    Joined:
    Sep 6, 2013
    Posts:
    56
    Hello,
    Four methods, CRUD, Insert(), Select(), Update(), Delete().
    put methods in One Box then Commit();
    Code (CSharp):
    1. using( var box = auto.Cube() ){
    2.   box["Table2"]...
    3.   box["Table3"]...
    4.   var cr = box.Commit();
    5. }
    or use AutoBox (= set autocommit=true).
     
  7. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    ok, thanks, that's a start atleast (some kind of documentation would still help though, XML/pdb/mdb). Another question: new DB(x) - i guess x has to be unique? what does it represent?
     
  8. Bruce3D

    Bruce3D

    Joined:
    Sep 6, 2013
    Posts:
    56
    DB.Root( path );
    new DB(x)
    when x is long : x is the ID of the DB;
    when x is byte[] : x is the Memory of the DB;
    when x is Stream: x is the Stream to read the DB, Readonly;
    when x is DB.CacheOnlyArg: like x is byte[0];

    iBoxDB is a custom-built database, it depends what users wanted, not what the DB provides.
    the standardized parts are CURD with a packing box.
     
    Last edited: Nov 4, 2017
  9. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    That was insightful, thanks.
     
  10. Batka

    Batka

    Joined:
    May 23, 2016
    Posts:
    22
    Hi, I really love your database, and I want to include it in my following projects.
    I am confused how to use the StreamingAssets folder as the path.

    In the following example you've posted,

    What type is the 'server' variable?
    I guess it's an instance of DB since it's instantaiting a new DB

    Code (CSharp):
    1. server = new DB (3);
    But then after the if/else, I see

    Code (CSharp):
    1. db = server.Open();
    This confuses me, what is db and what is server?...



    Thank you for your time :)
     
  11. Bruce3D

    Bruce3D

    Joined:
    Sep 6, 2013
    Posts:
    56
    Hi, it's a long story, in the old days, the concept of Database is Server.
    Code Updated.
    Code (CSharp):
    1. db = new DB (...);
    2. auto = db.Open(...);
     
  12. Batka

    Batka

    Joined:
    May 23, 2016
    Posts:
    22
    Gosh can't believe how powerful it is. Thanks a lot Bruce!
     
    Bruce3D likes this.
  13. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,080
    Looks cool but is there any PlayMaker actions for people can't code?
     
  14. antsonthetree

    antsonthetree

    Joined:
    May 15, 2015
    Posts:
    102
    I've downloaded this and it looks very nice so far. I have a couple questions.

    • I'm currently evaluating this vs LiteDB and was wondering if you, or anyone else on the thread could chime in on opinions of the two?
    • Second, is the source for iBox available? I do not see it in the download package.

    I don't mind using open source freeware, but without the source, if you get hit by a bus tomorrow (don't do that) that pretty much locks me into this version forever.
     
  15. Bruce3D

    Bruce3D

    Joined:
    Sep 6, 2013
    Posts:
    56
    Thanks, iBoxDB has a stable Interface, like five years ago, some databases changing every version.
    Using this version forever isn't a bad thing, actually many users don't upgrade to new version. you can use five years ago version, it works fine today.
     
    laurentlavigne likes this.
  16. Hi @Bruce3D , I'm currently evaluating nosql solutions for Unity. Your package looks very promising, I need some information though. Maybe I wasn't thorough enough, but I couldn't find out the legality about this project. What kind of license you have in mind? I guess it's free, since you allow us to download, but neither on your website nor in the package you're appointing to any licenses. I'm only allowed royalty-free licenses which can be used as part of paid products, that's why I'm asking. Could you please give some information about it? Optimally inside the package?
     
  17. Deleted User

    Deleted User

    Guest

    @Bruce3D Does iBoxDB have documentation? The website just contains examples.

    another question, is iboxdb backward/forward compatible?
     
    Last edited by a moderator: Feb 26, 2018
  18. Bruce3D

    Bruce3D

    Joined:
    Sep 6, 2013
    Posts:
    56
    Hello @SorenCoder,
    "documentation", follow Instinct, iBoxDB has no complex design.
    "backward/forward compatible", no guarantee.
     
  19. @Bruce3D thanks for adding License! Appreciate it!
     
  20. Bruce3D

    Bruce3D

    Joined:
    Sep 6, 2013
    Posts:
    56
    That's OK, it has been in there for five years.:cool:
     
    Deleted User likes this.
  21. blotzy

    blotzy

    Joined:
    Oct 4, 2016
    Posts:
    1
    I'm impressed by this project. It performs great and it's really powerful. However, the obfuscated dll makes debugging this library incredibly painful. Perhaps this wouldn't be as much of a problem if the documentation were better.
     
    laurentlavigne and Flavelius like this.
  22. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    If i understand correctly EnsureIndex creates indices (of keys if they match?)
    What i'm doing:

    EnsureTable<MyVector3Class>("Table", "X", "Y");
    EnsureIndex<MyVector3Class>("Table", "X", "Y");

    What i'm expecting: to have a table with keys X and Y that are also indices so they speed up queries.
    What i get: UnexpectedException: DB:TableIndexExisted Vertices@X#Y
    What am i doing wrong?
     
  23. Bruce3D

    Bruce3D

    Joined:
    Sep 6, 2013
    Posts:
    56
    Hello,
    Key is a type of Index, has a KEY flag. the default index when querying data.
    you can create an index with different order @Y#X
    Code (CSharp):
    1. EnsureIndex(... Y , X )
     
    Flavelius likes this.
  24. DADA_universe

    DADA_universe

    Joined:
    Mar 14, 2015
    Posts:
    38
    Any pointers for using iBoxDB for file storage (reading / uploading of image files, video files, text files, that sort of thing)?
     
  25. Bruce3D

    Bruce3D

    Joined:
    Sep 6, 2013
    Posts:
    56
    Hello,
    use MemoryStream.
    Code (CSharp):
    1. class FileObject{
    2.   long Id;
    3.   string Type;
    4.   MemoryStream Stream;
    5. }
    6.  
    7. class FileInfo{
    8.   long Id;
    9.   string Name;
    10.   string Author;
    11.   DateTime Time;
    12. ....
    13. }
    14.  
    if one of your files' size bigger than 2G, create your own big file system.
    Code (CSharp):
    1. string AllBigFileinOne ="/c/path.bin";
    2. FileStream bigfs=new FileStream(AllBigFileinOne ...);
    3.  
    4. class FileObject{
    5.   long Id;
    6.   long Position;
    7.   long Length;
    8. }
    9.  
    10. FileObject fo;
    11. lock(bigfs){
    12.   fo.Position = bigfs.Position;
    13.   fo.Length=len;
    14.   WriteFile(bigfs...);
    15.   Save(fo);
    16. }
     
    Last edited: Feb 24, 2019
  26. DADA_universe

    DADA_universe

    Joined:
    Mar 14, 2015
    Posts:
    38
    Thanks for this, I appreciate your response, but I still have to figure out how to use this. Wish there was more example code than currently exists, and of course, documentation like many have requested, or maybe a wiki. Thanks for sharing your work all the same, iBoxDB ticks a number of boxes that many other database systems do not manage to achieve in the same combination.
     
    Bruce3D likes this.
  27. Bruce3D

    Bruce3D

    Joined:
    Sep 6, 2013
    Posts:
    56
    Because many 3rd Components are using iBoxDB, maybe the global database path setting will have conflict,
    use local database path can avoid it.

    Global Database Path
    Code (CSharp):
    1. long db_id = 7;
    2.  
    3. var path = Application.persistentDataPath;
    4. DB.Root(path); //Global
    5. DB db = new DB(db_id);

    Local Database Path
    Code (CSharp):
    1. using System.IO;
    2. using iBoxDB.LocalServer.IO;
    3.  
    4. var path = Path.Combine(Application.persistentDataPath, "MyComponentName");
    5. Directory.CreateDirectory(path);
    6. DB db = new DB(db_id, path);
    7.  
    8. //Debug.Log(((BoxFileStreamConfig)db.GetConfig().DBConfig).LocalRootPath);
    Or using HashCode as DB-ID
    Code (CSharp):
    1. long db_id = GetHashId("MyProject", "MyComponent");
    2. DB db = new DB(db_id);
    3.  
    4. public static long GetHashId(string projectName, string componentName)
    5. {
    6.    long id = Math.Abs(projectName.GetHashCode());
    7.    id <<= 32;
    8.     long id2 = Math.Abs(componentName.GetHashCode());
    9.     id |= id2;
    10.     return id <= 0 ? 1 : id;
    11. }
    12.  
     
    Last edited: Aug 11, 2019
  28. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    334
    Hi @Bruce3D!

    iBoxDB looks amazing.

    Quick question - on start I would like to initialize the database with data parsed from a Json file, if the DB is empty.

    How would suggest I do this? Is there a way to detect whether this is the first time and the DB is empty?
     
  29. Bruce3D

    Bruce3D

    Joined:
    Sep 6, 2013
    Posts:
    56
    Hello @Colin_MacLeod !

    Two solutions:

    1. Copy file, faster
    Create database with data from other Console-Application, then ZIP and Copy the file("db1.box") from origin "DB.Root(PATH)" to destination "DB.Root(Application.persistentDataPath)", if File.Exists("{Path}/db1.box")==false,
    before "new DB(1)". No need to copy "db1.box.swp" if closed safely.
    // Small DB file size
    //db.GetConfig ().DBConfig.FileIncSize = 1;

    2. Add one more "Create()" method to load json
    Code (CSharp):
    1. using iBoxDB.LocalServer;
    2.  
    3. public class App{
    4.     public static AutoBox Auto;
    5. }
    6.  
    7. public class Helper{
    8.   public static AutoBox Create(json){
    9.     DB.Root(Application.persistentDataPath);
    10.     DB db = new DB(1);
    11.     var cfg = db.GetConfig();
    12.     cfg.EnsureTable<Player>("Player", "Id");
    13.     var auto = db.Open();
    14.     using (var box = auto.Cube())
    15.     {   // use "limit 0,1"
    16.         if (box.SelectCount("from Player limit 0,1") == 0)
    17.         {
    18.             //Load Json here
    19.             //foreach
    20.             // box["Player"].Insert(obj);
    21.             var cr = box.Commit();
    22.        }
    23.    }
    24.    return auto;
    25.   }
    26. }
    27.  
    28. App.Auto = Helper.Create(json);
    29.  
     
    Last edited: Oct 30, 2019
    Colin_MacLeod likes this.
  30. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    334
    Bruce3D likes this.
  31. unity_emt4Mpz8KBYwEA

    unity_emt4Mpz8KBYwEA

    Joined:
    Jan 25, 2018
    Posts:
    3
    Hi,

    Can you say how can I have a change listener for document keys and nested keys updates ?

    Thanks,
     
  32. juanitogan

    juanitogan

    Joined:
    Aug 18, 2017
    Posts:
    27
    I just finished testing iBox vs SQLite in my game, GRITS Racing, for a rather complex and large leaderboard system. Here's what I found, along with suggestions.

    I like that iBoxDB supports Unity for Window, Lixux, and Mac, all via a single "managed" DLL.

    SQLite4Unity3d supports Windows (if you fix their 32-bit DLL mixup [or use the libs included in Win 10]),
    Linux (not mentioned but find a libsqlite3.so and it works [likely already in the OS too]),
    and Mac (by relying on the OS version [included since OS X 10.4]).

    Suggestions for iBoxDB (as of v3.3.2 and 3.5):
    • Publish a CHANGELOG so we know what is changing and why. https://keepachangelog.com
    • Rewrite the docs. Currently, I have to read the website, the example script, and this forum to understand half of how to use iBox... and then still need to guess the other half.
      • Particularly, tell us things in "work order" instead of "feature order." That is, after the list of features, start with install, then object/table definition (DDL), then how to intantiate/open a DB, then DML, etc.
      • (Also, add a note for Unity install.)
    • Document **all** the methods, even if it is very short for now.
    • What does `EnsureIncrement()` do? Document incrementing better since it is a common need.
    • What is the point of `DB(localAddress)`? Really. Part of the filename, it appears. Anything else?
    • Let us set our own filename for the DB (especially since we may want more than one in a folder).
    • I would like to see byte[] arrays as indexable (just like they are in SQLite).
    • Why do we need to give the name of the table with every Get, Insert, Update, etc., since we've already associated an object with a table in `EnsureTable<>()`.
      • Instead, remember the association, lookup the type of object being inserted, and use that table.
    • Why use strings to give field names? Such as in `EnsureIndex<Item>("Items", "id", "name", "size")`.
      • Instead: `EnsureIndex<Item>("Items", Item.id, Item.name, Item.size)`.
      • If you need to specify the max length for a string or byte[] column, put it in a property attribute/annotation like so:
        • `public long id;`
        • `[MaxLength(20)]`
        • `public string name;`
    • Do not use decorators like `*` and `!` in `"*from"` and `"!from"`. Use overloaded parameters instead to set this.
      • DSL is messy enough and string-based DSL is just way too messy.
      • It's not clear what `*` and `!` mean either.
    • In rare cases, I shouldn't have to put a primary key on a table. `EnsureTable<Meta>("Metas")` should be enough.
    • Wow! The base files are HUGE at 4.5 MB plus a 2 MB swp file! Not exactly lightweight. Compare to SQLite at 5 KB for same minimal data.
      • (At smallest setting db1.box is still 0.9 MB... and little of that, if any, is reserved space either! It grows with each insert.)
      • Currenty at 2.4 MB and growing. Expected to max out at about 2 MB but am only at about 1/3 expected rows. SQLite is at 0.7 MB for same data.
      • I guess speed comes at the cost of size. ...
        • Nevermind: SQLite tests at a full 10x faster read with my data (same 7-column index with minor diff of first column being byte[] in SQLite and string(48) in iBox).
        • Strongly suspect that SQLite is simply better at using wide index for searching and sorting.
    • Show us more about how to use LINQ (such as Where() and OrderBy() etc.).
    • Not enough details on index optimizations:
      • Is an index still used if the Where clause contains fewer columns (like other DBs do)?
      • Are indexes sorted such that they should also include the OrderBy columns?
      • In other words, should I index just the Where columns, or should I also include the OrderBy columns?
    Ultimately, I went with SQLite because iBox was too big, too slow, and too much of a black box. Really uncomfortable with black boxes. Otherwise, I had high hopes for iBox. Terribly disappointed... but hopeful for its future. I still like what it is attempting to do, in theory.
     
    renyunhao, corn and laurentlavigne like this.
  33. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
    Does iBox have a query to fetch adjacent cells? Say if I want to store voxel data in blob and also stats of population of a grid representing the surface of a planet.
     
  34. renyunhao

    renyunhao

    Joined:
    Nov 2, 2015
    Posts:
    2
    The author has been disappeared for 3 years, the website and version no longer updated. The code is obfuscated, document is lacked, support is gone. So just like author's license: The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions.
     
    m0guz and laurentlavigne like this.