B4J Question [BANanoServer] [SOLVED] How does one perform CRUD Backend Functionalities within a BANanoServer Environment?

Mashiane

Expert
Licensed User
Longtime User
Ola

Whilst CRUD with BANanoSQL using BANanoServer is a breeze, unfortunately, I have not been able to figure out how to perform CRUD within the BANanoServer environment for backends like MySQL, MSSQL etc and would greatly appreciate even the slightest (explain it like I'm 5) example that one could use to close this important gap.

Q. Is it possible to be provided with an example that uses remote RDC if available?
Q. Is it possible to be provided with an example that uses MySQL / MSSQL (along the lines of how ABM works e.g. ABMFeedback example)
Q. Is it possible to be provided with an example that perhaps uses PHP with BANano.CallInlinePHP?

Thank you.
 

alwaysbusy

Expert
Licensed User
Longtime User
Once you reach the server, it is exactly the same as any other B4J server project. You did this a quazillion times yourself with ABM. It is the same jServer behind it.

A BANanoServer project uses WebSockets (just like ABM): in the SERVERPage part, make a function to do your CRUD e.g. the AddOnTheServer method in SERVERAbout and call it from the BROWSERAbout like in the demo.

So the framework would be:

SERVERPage
B4X:
Sub INSERTSomethingInDB(Something...) as Boolean
    ' normal B4J stuff to run an insert query in a database

    Return successOrNot
End Sub

BROWSERPage
B4X:
Dim value As Int = 0
Dim prom As BANanoPromise = ws.RunFunctionWithResult("INSERTSomethingInDB", Array(Something...))
prom.Then(value)
        Log("SERVER insert a success " & value)
prom.end

And because BANanoServer uses WebSockets, this communication is bi-directional! (see AddInTheBrowser)

The Main Class, SERVER and SHARED parts will be compiled to a JAR and runs on a VPS. BANano also generates the WebApp for the browser transpiling the BROWSER and the SHARED parts. So obviously, the SHARED parts must only use BANano compatible code but you can use #if B4J for specific SERVER parts which will be ignored by the Transpiler. Something like this can be SHARED for example:
B4X:
' This method can create a database on both the Server and Browser side
public Sub OPENDATABASEWait(DatabaseName As String)
    Dim Query As String = $"CREATE TABLE IF NOT EXISTS tRecords (uuid TEXT PRIMARY KEY, linkuuid TEXT, recordtype INTEGER NOT NULL, created TEXT NOT NULL, lastmodified TEXT NOT NULL, status INTEGER NOT NULL, syncstatus INTEGER NOT NULL, syncvalue TEXT DEFAULT '')"$
    #if B4J
        SQL.InitializeSQLite(File.DirApp, DatabaseName, True)    
        SQL.ExecNonQuery(Query)            
    #else
        SQL.OpenWait("SQL", DatabaseName)    
        SQL.ExecuteWait(Query, Null)
    #End If
End Sub

' This method can insert a record on both the Server and Browser side
public Sub INSERTRecordWait(Rec as SHAREDSyncRecord, FromUUID As String) As String
    Dim values As List = Rec.ToListRECORD(True)
    Dim Query As String = $"INSERT INTO tRecords (uuid, linkuuid, recordtype, created, lastmodified, status, syncstatus, syncvalue) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"$
    #if B4J
        Try
            SQL.BeginTransaction        
            SQL.ExecNonQuery2(Query, values)                    
            SQL.TransactionSuccessful
        Catch
            Log(LastException)
            SQL.Rollback
        End Try    
    #else
        SQL.ExecuteWait(Query, values)
    #End If
    Return rec.UUID
End Sub

So the big difference between a normal BANano WebApp and one using a BANanoServer is this:

In case of a BANanoServer project, your WebApp is served by Jetty instead of e.g. Apache and is using WebSockets to talk to this Jetty server.

The fun part about using a BANanoServer is that it kind of acts like node.js: you can access all the hardware (as the server part is a full blown B4J project) so ideal for an IoT project where the Webapp part is the interface a user gets and the Server part talks to the hardware. One could for example have a Raspberry Pi that regulates the temperature in your home, running the server part. And from any browser in the world, you can connect to this Jetty server and change the temperature. You get the best of both worlds using only one programming language: B4J!

Never used RDC myself but I'm sure there are plenty on this forum who did use it with a jServer. As for BANano.CallInlinePHP, you wrote tutorials yourself on this forum. It bypasses the BANanoServer (jetty) completely and talks directly to another server (PHP). BUT: as you are mixing servers (you Webapp basically talks to two different physical servers: a Jetty and a PHP server), chances are you will get CORS errors if not both are HTTPS (or other causes). I would avoid that and either use a BANanoServer (jetty) or a PHP server to do your stuff.

I believe you are overthinking this.

Alwaysbusy
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Question:
along the lines of how ABM works e.g. ABMFeedback example

Reply:
it is exactly the same as any other B4J server project

I was thinking the same - but I know nothing about BANano... (until u make it as easy as ABM - something my simple mind can comprehend.)

PHP? - what the hell is that? - Never mind - tried it - don't want to know.... (way too much work). Not B4X enough for me.

I believe you are overthinking this.

Or perhaps, not enough thinking about it (issue) before posting a question?
I ranted about this recently - posting a question where it could have been resolved with a little forethought and research.

My 2 pesos...
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
Thanks a lot for the clarity. Unfortunately for all of us there are demo projects in the Banano download and sadly not even a single example of a Crud based project using Banano Server.

At least for ABM we had the feedback example to take us through so that we can learn and then implement MySQL.

I will plead with you again. Can you please please please provide us with a demo project that uses MySQL as a backend and also MSSQL Banano Servers. I'm sure these will have the best practise that all of us can relate to and mostly learn from and not some trial and error exercise or some "steep learning curve."

If you don't want to I will perfectly understand and I am sure with the very intelligent people like Harris here in the forum who like helping other people if he knew how to and had a BananoServer based MySQL and MSSQL project that he could share with us he would have by now.

I mean how many people in the forum are talking about how mind blown are they about BANanoServer and how they have implemented their IoT, MyQL or MSSQL with it? Absolutely none. I stand to be corrected and I could be wrong.

I wonder why? They either don't know how, just like me and would like to know and people are just not sharing their experiences.

Also our minds interpret and understand things differently, there are slow learners and fast learners and sadly the issue with some intelligent people is that they usually don't understand when other people simply don't understand "easy things". Only when I put myself in the others person's "shoes" have I managed the utmost of patience with some of my students. Besides, there are for Dummies books all over the world for something as easy as boiling eggs and even cooking.

That is the exact reason Harris himself wrote ABM for dummies, appreciating that some other people might not necessarily understand the easy stuff and you came up with a very smaller simple template for dummies for ABM.

For example, we all at some stage didn't even have a clue about AddRows and AddColumns until someone wise wrote ABM for dummies. Someone else followed with a YT channel specifically dedicated to ABM.

As a dummy, people usually always want to find documentation, videos that would point them to the right direction even when things are "easy and simple" for others.

Erel dedicated time to even create a learning channel because things are not always as simple as we purport them to be for others.

This request is not only or just about me but for everyone else who might still find BANanoServer intimidating and would like to explore it but due to lack of documentation, video materials, examples, etc, might say, for now I duck, later.

People are still asking for B4W here whilst there is Banano!!! Simple answer. Documentation. Documentation. Documentation.

#PuppyEyes
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
So from what I understand, you've never written a jServer Handler, parsed the request, looked something up in a database, and returned the result to a browser? Well then, you are going to be thrilled with these links, as in BANanoServer, it is exactly the same! #Surprise 🥳


BANanoServer IS a jServer project! Rename the .b4xlib to .zip (use a tool like winzip to unzip it to a folder), and look at the source code. It is just B4J jServer source code, with handlers and WebSockets and all the other goodies Erel provided for us. If you do not know how to get started with B4J's jServer, I suggest you start at the very beginning with the above tutorials Erel wrote on how to get started with WebApps in B4J and try to UNDERSTAND it. Exactly the same videos, tutorials etc apply.

All the rest (MySQL, MQTT, Bluetooth, IoT and so on) is also PLAIN B4J stuff with plenty of tutorials and videos on this forum on these subjects. And as Erel explained in his tutorials, you can use all that stuff in a jServer project (hence in a BANanoServer project because, drum roll... it is a jServer where I made some convenient methods and handlers based on my experience so you can quickly move on the the logic of your app). Just put it in a SERVERPage class (explained here) as you would in any other Handler explained in Erels tutorials. You DON'T have to use it: just use a normal jServer and write the handlers yourself. Really, maybe I better never wrote that one and let you fall in the pitfalls of jServer that I encountered over the years and had to learn from...

These are libraries I wrote in my spare time, continuously learning the inner workings of web apps from other languages/resources on the interweb and giving them for free to the B4J community. Use them, or don't. A lot do I see in my 'thank you' mailbox so I'm happy enough.

And I make plenty of time answering questions about my libraries (I practically live here), how basic they may be. All the other stuff is on this forum, explained by people who know a lot more about them than me.

Alwaysbusy
 
Upvote 0
Top