Version: 4.30
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 (for B4A, B4i and B4J), MariaDB and MySQL (B4J only).
Private DB As MiniORM
Private MS As ORMSettings
MS.Initialize
MS.DBType = "SQLite"
MS.DBFile = "data.db"
MS.DBDir = File.DirApp
DB.Initialize
DB.Settings = MS
If DB.Exist Then
LogColor($"${MS.DBType} database found!"$, COLOR_BLUE)
DB.Open
Else
LogColor($"${MS.DBType} database not found!"$, COLOR_RED)
CreateDatabase
End IfNote: Before calling DB.Create and DB.Insert, set DB.QueryAddToBatch = True
DB.Initialize
DB.DbType = DB.SQLITE
DB.QueryExecute = False
DB.Table = "categories"
Log(DB.Statement)#If MySQL Or MariaDB
Wait For (DB.CreateDatabaseAsync) Complete (Success As Boolean)
#Else
Dim Success As Boolean = DB.InitializeSQLite
#End IfDB.SQL = DB.OpenDB.Table = "tbl_categories"
DB.Columns.Add(DB.CreateColumn2(CreateMap("Name": "category_name")))
DB.CreateDB.Columns = Array("category_name")
DB.Insert2(Array("Hardwares"))
DB.Insert2(Array("Toys"))Wait For (DB.ExecuteBatchAsync) Complete (Success As Boolean)
If Success Then
Log("Database is created successfully!")
Else
Log("Database creation failed!")
End If
DB.CloseDB.Table = "tbl_categories"
DB.Query
Dim Items As List = DB.ResultsDB.Table = "tbl_products"
DB.Columns = Array("category_id", "product_code", "product_name", "product_price")
DB.Id = 2
DB.Save2(Array(Category_Id, Product_Code, Product_Name, Product_Price))DB.Id = 3
DB.SoftDeleteDB.Id = 4
DB.DeleteDB.Destroy(Array(2, 3))Dim Rows As Int = DB.RowCountDim Data As Map = DB.Find(2)DB.Table = "tbl_products"
DB.Conditions = Array("category_id = ?", "product_price > ?")
DB.Parameters = Array(2, 50)
DB.OrderBy = CreateMap("id": "DESC")
DB.Query
Dim Data As List = DB.ResultsDB.Table = "tbl_products p"
DB.Columns = Array("p.*", "c.category_name")
DB.Join("tbl_categories c", "p.category_id = c.id", "")
DB.WhereParam("c.id = ?", CategoryId)
DB.Query
Dim Data As List = DB.Results