Version: 6.04
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).
Dim DB As MiniORM DB.Initialize
DB.Initialize DB.DbType = DB.SQLITE DB.QueryExecute = False DB.Table = "categories" Log(DB.Statement)
DB.Settings.DBFile = "app.db"DB.Initialize Dim MS As MiniORMSettings MS.Initialize MS.DBType = DB.MYSQL MS.JdbcUrl = "jdbc:mysql://{DbHost}:{DbPort}/{DbName}?characterEncoding=utf8&useSSL=False" MS.Driver = "com.mysql.cj.jdbc.Driver" MS.DBName = "app" MS.DbHost = "localhost" MS.User = "root" MS.Password = "password" DB.Settings = MS
#If MySQL Or MariaDB Wait For (DB.ExistAsync) Complete (DbFound As Boolean) #Else Dim DbFound As Boolean = DB.Exist #End If If DbFound Then LogColor($"${DB.DBType} database found!",ドル COLOR_BLUE) Else LogColor($"${DB.DBType} database not found!",ドル COLOR_RED) CreateDatabase End If
#If MySQL Or MariaDB Wait For (DB.CreateDatabaseAsync) Complete (Success As Boolean) #Else Dim Success As Boolean = DB.CreateSQLite #End If
DB.OpenDB.Table = "categories" DB.Columns = Array("category_code", "category_name") DB.Create
DB.Table = "products" DB.Columns.Add(CreateMap("N": "category_id", "T": DB.INTEGER)) DB.Columns.Add(CreateMap("N": "product_code", "S": 12)) DB.Columns.Add(CreateMap("N": "product_name")) DB.Columns.Add(CreateMap("N": "product_price", "T": DB.DECIMAL, "S": "10,2", "D": 0.0)) DB.Columns.Add(CreateMap("N": "product_image", "T": DB.BLOB)) DB.Foreign = "category_id" DB.References("categories", "id") DB.Create
DB.Columns = Array("category_id", "product_code", "product_name", "product_price") DB.InsertWithParams = Array(2, "T001", "Teddy Bear", 99.9) DB.InsertWithParams = Array(1, "H001", "Hammer", 15.75) DB.InsertWithParams = Array(2, "T002", "Optimus Prime", 1000)
Wait For (DB.ExecuteBatchAsync) Complete (Success As Boolean) If Success Then Log("Database is created successfully!") Else Log("Database creation failed!") End If DB.Close
DB.Open DB.Table = "categories" DB.Query
DB.Open DB.Find(3) If DB.Found Then Log(DB.First) End If
Dim Data As List = DB.Results
DB.Table = "products" DB.Columns = Array("category_id", "product_code", "product_name", "product_price") DB.Id = 2 DB.SaveWithParams = 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.RowCount
DB.Table = "products" DB.Conditions = Array("category_id = ?", "product_price > ?") DB.Parameters = Array(2, 50) DB.OrderBy = CreateMap("id": "DESC")
DB.Table = "products p" DB.Columns = Array("p.*", "c.category_name") DB.Join("LEFT", "categories c", Array("p.category_id = c.id")) DB.WhereParam("c.id = ?", CategoryId)
DB.ShowExtraLogs = TrueDB.QueryAddToBatch = True