Ola
With the upcoming updates to BANano 7, with cron jobs, background workers, it makes it more awesome to work with. So i guess we can only be limited by our own imagination. Hand clap to Alain for such an amazing software package.
So what is BANanoRelax?
BANanoRelax is a DB lib, made of PouchDB (Client) + CouchDB (Server).
1. You can work offline - it creates an indexedDB for you and you can use like how how you usually use BANanoSQL. As its not compatible with BANanoSQL,you cant use BANanoSQL commands.
2. This stores your data using an "_id" and a "_rev", this can either be your own specified id or use the BANano.GUID with (BANano.GenerateUUID). The "_rev" is generated automatically.
3. Using your own IDs is recommended.
4. Has a simple API for CRUD functionality.
CRUD Example - The BANano.Await() Version
1. Initialize the lib and tell it you want to work offline. By working offline, a local IndexedDB "todos" database is created. This is the recommended approach. And yes you can just work online with db.WORK_ONLINE.
2. Create a record - think of it as the PUT
When we initialized, we said we want to use own ids, so our id here is "1"
Result:
3. Read a record (using own id) - this of it as the GET
Result
4. Update a record (using own id) - another PUT
'* here we are using the previous record we read, you can pass it any map object
Result
'
5. List all records
Result
6. Delete a record (using own id) - think of it as the REMOVE
Result
7. Sync with clould DB (this is 2 way to cloud and from cloud)
8. Relax
So far tests are yielding good results.
CRUD Example - The BANano.CallBack() Version
For each CRUD call you make, you need to trap the result with a callback.
[Coming Soon]
So how do you get started with this?
Ta
#SharingTheGoodNess
With the upcoming updates to BANano 7, with cron jobs, background workers, it makes it more awesome to work with. So i guess we can only be limited by our own imagination. Hand clap to Alain for such an amazing software package.
So what is BANanoRelax?
BANanoRelax is a DB lib, made of PouchDB (Client) + CouchDB (Server).
1. You can work offline - it creates an indexedDB for you and you can use like how how you usually use BANanoSQL. As its not compatible with BANanoSQL,you cant use BANanoSQL commands.
2. This stores your data using an "_id" and a "_rev", this can either be your own specified id or use the BANano.GUID with (BANano.GenerateUUID). The "_rev" is generated automatically.
3. Using your own IDs is recommended.
4. Has a simple API for CRUD functionality.
CRUD Example - The BANano.Await() Version
1. Initialize the lib and tell it you want to work offline. By working offline, a local IndexedDB "todos" database is created. This is the recommended approach. And yes you can just work online with db.WORK_ONLINE.
B4X:
'initialize the db and use own ids
Public db As BANanoRelax
db.INITIALIZE(Me, "todos", False)
'specify connecction details for online sync / work online
db.Host = "127.0.0.1"
db.Port = "5984"
db.UserName = "XXX"
db.Password = "XXX"
db.WORK_OFFLINE
2. Create a record - think of it as the PUT
When we initialized, we said we want to use own ids, so our id here is "1"
B4X:
Dim person As Map = CreateMap()
person.Put("_id", "1")
person.Put("firstname", "Anele")
person.Put("lastname", "Mbanga")
Dim res As Map = BANano.Await(db.PutWait(person))
Log(res)
Result:
3. Read a record (using own id) - this of it as the GET
B4X:
Dim rg As Map = BANano.Await(db.GetWait("1"))
Log(rg)
Result
4. Update a record (using own id) - another PUT
'* here we are using the previous record we read, you can pass it any map object
Result
B4X:
rg.Put("firstname", "Usibabale")
Dim ru As Map = BANano.Await(db.UpdateWait("1", rg))
Log(ru)
5. List all records
B4X:
Dim recs As List = BANano.Await(db.GetAllWait(True))
Log(recs)
Result
6. Delete a record (using own id) - think of it as the REMOVE
B4X:
Dim rd As Map = BANano.Await(db.RemoveWait("1"))
Log(rd)
Result
7. Sync with clould DB (this is 2 way to cloud and from cloud)
B4X:
db.SYNC(True)
8. Relax
So far tests are yielding good results.
CRUD Example - The BANano.CallBack() Version
For each CRUD call you make, you need to trap the result with a callback.
[Coming Soon]
So how do you get started with this?
- Install CouchDB (specify admin and password names - keep these safe, you will need for sync. This is the server part. I will avail the client part sometime next week.
- Check CouchDB is running; http://127.0.0.1:5984/ (observe the JSON result)
- Open Fauxton on: http://127.0.0.1:5984/_utils/
- Enable CORS : http://127.0.0.1:5984/_utils/#_config/couchdb@localhost/cors (this helps with sync and replication)
Ta
#SharingTheGoodNess
Attachments
Last edited: