modgen-b4j
version: 0.60GitHub: https://github.com/pyhoon/modgen-b4j
Usage:
- Put the jar in B4J additional libraries folder
- Add the macro to Main
- Add a code or class module e.g UsersModel
- Inside Sub Process_Globals or Sub Class_Globals, add a type e.g Type Users (user_name As String, admin As Int)
- Place the cursor or click inside Sub Process_Globals or Sub Class_Globals
- Invoke macro: ModelGenerator. Wait until logs Completed. Exit code: 0
B4X:
#Macro: Title, ModelGenerator, ide://run?file=%ADDITIONAL%\modgen.jar&Args=%STATE1%&codesync=True
UsersModel.bas:
Sub Process_Globals
Type Users ( _
user_name As String, _
user_email As String, _
user_mobile As String, _
password_hash As String, _
password_salt As String, _
user_image() As Byte, _
admin As Int, _
active As Int)
End Sub
The generated code will be appended at the bottom of code module or class immediately.
B4X:
Public Sub CreateUsersTable
Dim DB As MiniORM
DB = Main.DB
DB.ShowExtraLogs = True
DB.UseTimestamps = True
DB.QueryExecute = False
DB.QueryAddToBatch = True
DB.IfNotExist = True
Log("Creating Users table...")
DB.Open
DB.Table = "tbl_users"
DB.Columns.Add(CreateMap("Name": "user_name", "Null": False))
DB.Columns.Add(CreateMap("Name": "user_email", "Null": False))
DB.Columns.Add(CreateMap("Name": "user_mobile", "Null": False))
DB.Columns.Add(CreateMap("Name": "password_hash", "Null": False))
DB.Columns.Add(CreateMap("Name": "password_salt", "Null": False))
DB.Columns.Add(CreateMap("Name": "user_image", "Type": DB.BLOB))
DB.Columns.Add(CreateMap("Name": "admin", "Type": DB.INTEGER, "Default": "0"))
DB.Columns.Add(CreateMap("Name": "active", "Type": DB.INTEGER, "Default": "0"))
DB.Create
Wait For (DB.ExecuteBatchAsync) Complete (Success As Boolean)
If Success Then
Log("Table Users created successfully!")
Else
Log("Table Users creation failed!")
End If
DB.Close
DB.QueryExecute = True
End Sub
You can then call the sub using the following code:
B4X:
UsersModel.CreateUsersTable
Attachments
Last edited: