B4J Library Palantech Framework

It's with great pleasure that i am releasing the first ever ORM MVC B4J Framework.

What does that mean?

ORM: Object Relational Mapping, This framework allows you to pull from and push data to a database without writing SQL, this is done using the awesome Type system that we all love in B4x
MVC: Stands for Model View Controller. you can read about it here: https://en.wikipedia.org/wiki/Model–view–controller
B4J: The IDE that we all love! (please check footnotes)

Just to give you an idea of what palantech is i took some inspiration to build palantech from giants like Ruby on Rails, Phoenix + Elixir and Django + Python.

What can you do with palantech?
Right now is specialized on webapps but it also has some B4I and B4A intercommunication so you dont have to touch any of SQL or JSON between all the platforms.

How do i use it?
as an MVC framework you need to think in 3 parts:

The model is based on the type system:
Create a Type:
Type user (id As String, name As String, created_at As Long, updated_at As Long)
Pull from Database:
private Sub get_user(sql As SQL, id As String) As user
    Dim qb As query_builder
    qb.Initialize("user")
    Return qb.get_one(sql, id)   
End Sub
Interact with the type:
private Sub interact_with_user(sql As SQL)
    Dim user As user = get_user(sql, "uuid")
    user.name = "enrique"
    DB_ORM.save(user,sql)
End Sub

The view is a wrap of the Freemarker Library (https://freemarker.apache.org/)

This library allows to work seemlesly from HTML with data we already processed in B4J (types, maps, list, primitives)
1666313836518.png

We are setting (in HTML) the value of the user.name notice the "${}"
When the user submits this input (wrapped in a form tag) to B4J the ORM will convert it to a type
POST parameters to Type:
Dim params As Map = utils_web.get_parameters(req)
Dim obj As user = HTTP_ORM.build_from_req("user", params)

And the Controller
You already use them on Jserver

I hope that so far you like the concept!

How can i get it?
i am first releasing it in a closed beta with the idea of getting feedback. If you have ever done business with me, donated to me or i have donated to you, you are eligible to enter! send me a PM.

(PLEASE NOTE: don't donate to get a copy, the idea of the closed beta is so i can focus on each user to receive feedback and improve the product, if you believe that you can contribute to the product send me a PM too)

You will receive the library and an example of its usage.

Caveats and Limits
Currently works with SQL Server and MySQL
The DB ORM requires that your database adheres to a standard, some examples:
  • All tables must have an ID, all foreign keys must end as _id
  • All numeric values (except for int) will be converted to Double
  • Each db datatype must have a counterpart on B4x so sometimes an obscure datatype may be not available
  • And some others
I have some limited time

Libraries
Currently the only non official library you need is Hikari: https://www.b4x.com/android/forum/threads/hikaricp-5-x.138846/
And external jar files, download this one: https://freemarker.apache.org/freemarkerdownload.html

Special Thanks
to @aeric that helped me in creating the MySQL interface and contributing to the framework with code and ideas.

Hope you like it!
 

Magma

Expert
Licensed User
Longtime User
@EnriqueGonzalez Sorry, I feel dumb... or stayed at old ways... can you explain with an example...

a) If i want to get a value from specific table and field... what will be the command... ?
b) if i want to save a value to a " " ?
c) if i want to search for specific table for a value that may be in specific field ?

sorry for dumb questions... i didn't understand it... I am sure that is something good ! :)
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
If i want to get a value from specific table and field... what will be the command... ?
hi Magma! as a convention the table has the same name as the type (type: user, table: users)
B4X:
Dim qb As query_builder
    qb.Initialize("user")
this code is the same as
SQL:
SELECT *
    FROM users
if i want to save a value to a " " ?
then if you already have a type for example user that has a name you just need to do:
B4X:
    dim user as user = DB_ORM.create_empty_model("user") ' or from an existing record on DB
    user.name = ""
    DB_ORM.save(user,sql)
The DB_ORM chooses to either create and UPDATE or an INSERT depending on the situation

if i want to search for specific table for a value that may be in specific field ?
if you just want one single field you could also do:
B4X:
    Dim qb As query_builder
    qb.Initialize("user")
    qb.selected_fields(array as string("name"))

sorry for dumb questions
No question are dumb! MVC frameworks are rather old but on B4x there are very few examples, most notably miniORM by Aeric
 

Magma

Expert
Licensed User
Longtime User
hi Magma! as a convention the table has the same name as the type (type: user, table: users)
B4X:
Dim qb As query_builder
    qb.Initialize("user")
this code is the same as
SQL:
SELECT *
    FROM users

then if you already have a type for example user that has a name you just need to do:
B4X:
    dim user as user = DB_ORM.create_empty_model("user") ' or from an existing record on DB
    user.name = ""
    DB_ORM.save(user,sql)
The DB_ORM chooses to either create and UPDATE or an INSERT depending on the situation


if you just want one single field you could also do:
B4X:
    Dim qb As query_builder
    qb.Initialize("user")
    qb.selected_fields(array as string("name"))


No question are dumb! MVC frameworks are rather old but on B4x there are very few examples, most notably miniORM by Aeric
To see if understand.. so the "framework" decides at what table will save the value? or you are selecting it by the type -- but how ?

...The other answers -> were very clear :) thanks.... using such a framework you are avoiding a lot of typing :)
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
To see if understand.. so the "framework" decides at what table will save the value? or you are selecting it by the type -- but how ?
when you initialize the ORM you pass the type (user) and its table name (users) you could change the name of the table but by convention the table should be the plural of the type

using such a framework you are avoiding a lot of typing
yes thats one feature among many
 
Top