Version: 1.14
A mini object–relational mapping (ORM) that can be use for creating db schema and SQL queries. It is suitable for Web API Template or any database system. Currently it supports SQLite and MySQL (B4J).
Dim MDB As MiniORM
MDB.Initialize(Main.DBOpen, Main.DBEngine)
MDB.UseTimestamps = True
MDB.AddAfterCreate = True
MDB.AddAfterInsert = True
Note: Before calling MDB.Create and MDB.Insert, set AddAfterCreate and AddAfterInsert to True.
MDB.Table = "tbl_category"
MDB.Columns.Add(MDB.CreateORMColumn2(CreateMap("Name": "category_name")))
MDB.Create
MDB.Columns = Array("category_name")
MDB.Insert2(Array("Hardwares"))
MDB.Insert2(Array("Toys"))
Wait For (MDB.ExecuteBatch) Complete (Success As Boolean)
If Success Then
Log("Database is created successfully!")
Else
Log("Database creation failed!")
End If
MDB.Close
MDB.Table = "tbl_category"
MDB.Query
Dim Items As List = MDB.Results
MDB.Table = "tbl_products"
MDB.Columns = Array("category_id", "product_code", "product_name", "product_price")
MDB.Id = 2
MDB.Save2(Array(Category_Id, Product_Code, Product_Name, Product_Price))
MDB.Id = 3
MDB.SoftDelete
MDB.Id = 4
MDB.Delete
MDB.Destroy(Array As Int(2, 3))
Dim Rows As Int = MDB.RowCount
Dim Data As Map = MDB.Find(2)
MDB.Table = "tbl_products"
MDB.Where = Array("category_id = ?")
MDB.Parameters = Array As String(2)
MDB.OrderBy = CreateMap("id": "DESC")
MDB.Query
Dim Data As List = MDB.Results
MDB.Table = "tbl_products p"
MDB.Select = Array("p.*", "c.category_name")
MDB.Join = MDB.CreateORMJoin("tbl_category c", "p.category_id = c.id", "")
MDB.WhereValue(Array("c.id = ?"), Array(CategoryId))
MDB.Query
Dim Data As List = MDB.Results