Appwrite, an alternative to Firebase in Flutter apps! Pair programming with the expert!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Applause] hello and welcome to muddar today i'm very excited we're going to talk about upright and alternative to firebase as they indicate so i have one of the best flutter developer in the world and youtuber as well as a google developer expert with me who is also working on app right you know software or web application or whatever you want to call it actually and he's going to talk about why app right is awesome and then he will per program with me to implement like upright into my famous mj coffee app hello edamudder how is it going hey thank you thank you for great introduction you flatter me and it's great it's great i'm and i'm really excited to be here talk about app right and flutter yeah uh it's very exciting to have you in this show it's it's a pleasure to have you on board uh can you introduce a little bit josef and also tell us about upright and your relation with app right and you know everything around that okay sure so firstly i am damodar luani from kathmandu nepal uh one of the google developer expert from 2020 and i have been working with flutter for almost three years now uh yeah more than two years almost three years and getting into app right was one of the thing led because of flutter so i was exploring flutter and i was exploring all the open source technologies that i could work with flutter that i could use with flutter to make great applications uh during my flutter work and during that time i was also making some youtube tutorials with flutter and firebase and i was looking for other alternatives to firebase not only to show it in my tutorials but also to use it for my personal projects as well i was looking for open source alternatives and that is how i came to know about app right and once i get to once i started using it it was so simple it was all built on docker and i had previously used docker so it was simple to get it started for me so i started making tutorials regarding that and then during that time uh i got a chance to talk to the founder of app right or the sole owner of app right at the moment uh eldad he's a great guy he helped me a lot during my tutorial so i was recording tutorials regarding upright i would have some issues with their flutter sdk i would go back to him i would ask questions i get feedback and during that time i also got a chance to like contribute to their flutter sdk i implemented web support and all those things at that time i was not working with app right i was merely contributing it to as an open source project and later because of all this and that i was already a active community member in app right i got chance to work with app right and now talking about app right app right is an open source backend as a service much like firebase it handles many of the uh like many of the repeated activities that mobile and web developers need for their applications like databases user management storage cloud functions all those kind of things and it is like it provides all those services it is secure and it has nice console it has everything built in and it's built from scratch with docker support and it is built with like a scalability in mind it is still an ongoing project though it is not a stability many of us are already using it in production as well so that's all about app right and me thank you all right perfect uh so i guess that's uh you know now we know upright a bit and that's great so i used to build my one of my application mj coffee app which we're gonna pay a program today on that with firebase i also have tutorial on firebase on pluralsight and you know i spend a lot of time on flutter and firebase but yeah when i when i get to know app right i was very excited because you know i'm a big fan of having competition in this world you know it's it's it's nice to have you know several players uh not just one you know let's say player and that's only firebase for example and that's very exciting and as far as i understood let me open up this website for pop.dev here is the package so we understood that you support clutter and there is an upright uh flutter sdk yes uh first of all uh one question here is that are you also part of the team to develop this sdk like you are an author of this sdk one of the other perhaps yes so talking about sdk uh there is interest one interesting thing we generate our sdk using our own inbuilt tool in-house tool we generate all our sdks using that and swag respect so our api generates a swagger spec file and using that spec we automatically generate our sdks using some tweak templates right so i'm one of the lead developer are working on flutter as well as other sdks of app right this sounds very interesting uh so so it means that you kind of like all of your sdks are synced uh in in some words like you generate as soon as there is a new api let's say or new change then all the sdks not just in dart and flutter for example in all the other languages will get the newest update right because you are auto generating everything we are using swagger respect so once our api is updated our respect gets up updated and we generate the sdk using the new spec so we have all the sdks in sync all right that's fantastic so we're gonna come back to that later and talk about like how you can do that this is interesting as well but then today our main focus is on uh app right and how i can rewrite my application at the moment uh with app right but before we get into the application one question yes um how can you tell me like why should i use app right for example instead of firebase for example let's say okay so i am a firebase user myself i have been using firebase for quite a lot of times i have multiple uh flutter projects production level projects for my uh for my clients as well as my own uh running with firebase right but there are some issues with firebase let's not say issues but there are some what do we say there are some parts of firebase that i do not like at the moment like uh query querying the firestore database right if we want to make a query with text sorts or full text sites or any kind of search it's a pen we have to integrate whole another tool right we have to integrate our elasticsearch or something that is one thing next the user management or assigning roles to user role best user management that is another set of complications though we can use like custom claims and we can even use firestore database uh for saving the roles it is another set of pain that i feel with uh firebase and yet another set of pain that i felt with firebase feel with firebase is the permissions so we have to write a permission in whole different language that is somewhat like javascript or json right and there is not a lot we can do about permission there are some advanced stuff but even with permission uh if i want to read database in the permission to get data and compare my user data with request data with the actual data it will incur the read cost right it will add to the read cost all these challenges of firebase led me to find alternatives to firebase and i looked into many alternatives uh at the moment uh and one that supported flutter from beginning was upright and for me why app right was better than firebase for most many of my projects was because one the users and role management with teams and roles it's great like we can manage any kind of user scenario like admin uh user scenario or any complex scenarios with multiple teams and multiple groups roles in each group uh with app right easily next thing is permission for database we have individual document level permissions uh with users roles teams right so we can assign permission to individual documents and then even for storage files we can assign permission to individual files so that was another thing that led me to app right and another most important thing for me was it was open source i could self-host it on my own server so these were the things that led me to use upright that's fantastic so i think one of the very interesting parts when it comes to app right for me personally is that i can run app right like as a docker you know images or containers in my machine right so which means i can actually deploy those dockers in my own server and host it on my own infrastructure is that also something that i okay i understood it correctly this is actually very exciting so but then does it mean like if i use docker and like run all of the infrastructure for app right and my own infrastructure for example then how do you charge me how do you make money so if i use all of your services on docker and everything works okay at the moment we do not charge you we do not want to charge you we do not want to make money from it because we are a open source model company um i i don't want to go into details because i'm not the right person but we have some funding and we'll maybe soon we'll have some announcements regarding our funding as well and right now we are working to make the product open and best and later we will have our own cloud hosted solution like firebase has from where we will start monetizing but at the moment we are just focused on making the product great not on monetizing it okay you know i already uh fell in love with upright so this only this feature you know it just made me so excited about it like i can use the product on my own infrastructure and scale it up or scale it down as i want and that's fantastic all right great now let's go to my code base and my mj coffee app this is my famous app that i always program with different people on this app to make it perfect add different features and today i used to use firebase for this app but now i decided somehow to replace firebase with app right and i want you to help me to implement app right so i actually got rid of the whole firebase stuff in this application at the moment so it's pure it's clean there is no uh back-end for that at the moment so we can actually implement app right all right and as always you also have full access to my code base we are live share in vs code so we can pair a program together so let's get started first thing first perhaps i need to run that docker version of app right right yes so or is there any other solution uh right now you need to run one command that you can get from app right dot io if you go to app right dot io and type okay get the started button um here we go get this started button all right copy that because you are on mac right you should copy the user yeah i am on mac you can click to copy and then go back to your terminal and just make sure docker is installed yeah that's it yeah i do have i do have the docker well maybe it's not running but let's make sure i do have docker okay now to start it so let me now run my docker command here which i copied um [Music] oh okay here we go it's going to download it because it might take some time but let's uh move on to the next step what should i do for the next step okay so once you have installed uh locally or in a vm you have a domain assigned or anything you need to go to your local host right if you have installed logo right otherwise you can go to your domain and then you will access the app right console where if you are moving there first time you can sign up otherwise you can sign in with your uh your email and password once you get right you'll see the list of your projects if you don't have one you can create a new project all right all right once you have a project you can tap on that project to get to the project dashboard but let's take a moment and talk about the the the technology behind it so when docker comes up so what type of database or what type of web server i will i will need to face with it okay so talking about the infrastructure or what's behind upright is stack uh there are a couple of things uh for the web server we are using phpsoul uh it's the multi-threading multi-threaded architecture of uh php server uh with soon and then we have um at the moment mariadb database right and upright database is built on top of mariadb database so app right database is a kind of nosql or document based architecture built on top of the mariadb database and then we have yeah we have a soul server with rest api and then we have a websocket server right now from version 0.10 we have a real-time server with websocket so that is what we have and there are a bunch of other services behind the scene like we have email service that you can integrate your email smtp server and then we have other services like uh certificate service for automatically generating the ssl certificate uh so there are bunch of other service behind the scene working to make it great all right okay got it but that's interesting but first of all uh the doctor is asking me a couple of questions i'm just going to answer like quickly but then you know probably we need to answer it properly don't worry if you are watching that that's fine um but yeah go ahead uh running it locally you can answer all all with default answers because it's just uh some port default port is 80 and 443 for http and https then there is a secret key that is the encryption key and then there is a host name if you have a domain set up if you are setting it for the server you need to set up the host name and the custom domain as your own domain otherwise for local setup you can just uh keep all the default options all right actually that's interesting you said that you're running the infrastructure for the database uh on top of mario db which is like a relational database right but then you you provide to us like a non-relational abstraction or database yes is that so app right builds a document based architecture on top of the maria dv at the moment and uh one interesting thing we are going to a massive database refactor to support more underlying capabilities of our database system as well as it will still be a document based architecture but we'll be able to support mariadb even mongodb and postgres with our upcoming refactor and we'll have a lot more features oh yes that's interesting so that means that like later uh when you do this refactoring i can just go and choose the engine of my database i can say i want or i want even mario db as sql database not no sql database right yes no no not as sql we can't access it as sql it will still be a document based architecture on top of mariadb but we are adding a lot more capabilities like adding indexes and unique values assigning unique values to attributes a lot more things are coming you can check the progress it's open source so you can always check out pr's what's going on so apart from that it will still be a document based architecture like nosql on top of any relational or non-relational database that we support all right very good so it seems like my docker is installed and now i have the dashboard ready i have already created a project flutter original to just save some time so here is my dashboard right now so my dashboard locally is ready one question here so i have nothing here but i can i can see i can create database storage and user function and all of things that's great but one question here is that is this docker infrastructure which i just you know spin it up um is it production ready can i just like spin that up in my like let's say an uh cloud infrastructure like aws and don't care about anything else like security-wise or performance-wise how how does that scale should i take care of that or will you take care of that or how does that work at the moment okay talking about security and everything else uh it's quite good it's production ready you can host it you can just run it uh but during the setup you were asked a couple of questions like default ports and then security key you need to add your own proper security key uh apart from that everything else is like even database passwords are auto generated uh not here you can auto generate it but locally uh while setting this up directly in locally it's not like actually good for production if you set this up you need to change some environment variables so once you set it up it creates a folder called upright inside which there are two files dockercompose.aml file and then dot enb file right so you need to edit edit the dot env file there are a couple of environment variables that you might want to change like database passwords and then a couple of other things like security keys and then some other things are like good with default but you need to change passwords and default keys as well as you might want to change the cloud functions that are supported by default there are five or six cloud functions that are loaded you might want to keep it low or only to those uh languages or platforms that you want like we support six or seven different uh cloud functions php node.js dart right so you might want to enable only the one that you will use to save some spaces and everything i see okay sounds great sounds great okay uh let's actually go to the flutter uh application so i'm gonna get started with my i have already my you know um back-end ready and i'm gonna go and install it in my flutter app so i would assume that we need to install the sdk first right in public yaml file yeah okay so now i'm gonna actually install uh this uh sdk so well as always i think i can just install it with my uh um pubspec assist and what is it is it app right only right yes let's uh move on so now it's added to my dependencies um all right good so what should i do here is my main we got pop got pop get is ran right so we should have the power right i will make sure let's actually see i will make sure that it's actually run yeah that's great okay that is okay now we need to import it yes here we go uh is there any like let's say for example in firebase we need to initialize fire a firebase you know and then everything else will work is it like similar approach we need to do it uh somewhere even before run app or how does that work no it's uh we can do it anywhere because it's it's all api calls and sdk just handles uh makes it easy to set up some headers and everything you can basically do this without sdk just using our rest api but sdk makes the setup set up a lot easier but setup can run anywhere uh so but then uh okay that's good but then how is the best approach here should i uh like create my client for upright let's say here or should i just do it somewhere else or i mean here what i mean here is that like before run app uh in main or should i do it somewhere else i try what i do usually is i create a singleton class called upright service or anything and then there i initialize all my clients uh upright clients like database and okay well actually i do have some single songs already but maybe i can copy one of this for example let's say app right service let's call it do you agree yeah and then let's go there let's actually change us to upright service okay and i'm gonna actually delete the rest of the things here so here is my uh okay my service should i uh like create my client here um let's import and then let's create a client inside initialization uh yeah client uh you can make it late late client um yeah sure uh i i can actually sorry yeah you can you can also create an instance there that's so it's already actually imported from app right so it's uh it's over there right that's good yes so another what else should i do so now uh in the factory method can we access this client inside factory method yeah or another thing maybe we can create actually a method to initialize it like let's say you need yeah let's make a neat method okay so then we need client set set endpoint because that's the first thing i need to do right yeah okay what is the endpoint so this is the url this you'll actually get it from uh the dashboard if you go to the dashboard in the console app right console okay you added projects yeah if you go to settings click on settings so here you have your project id and api endpoint these are the two things that we need okay these two yeah that's good so let's copy then this one here we go actually i will quickly replace this and then uh you can chain another method right after set end point you can change set project okay then the next step is to set a project and that's probably the value that you mentioned here right yes all right so this is going to set my project yes and if you are uh working locally uh in local host and uh you are using https instead of st right then we need a self self sign certificate because locally we don't have actual certificate it's working with self-signed certificate right so we need to change another method uh after set project that is set self signed uh okay okay can pass through there yeah here we go or you can default is true you can either pass through or if you can even leave it as it is so uh we are just basically telling the sdk to accept the self-signed certificate all right that's good uh there is a typo here let me fix it quickly so here is uh the whole thing is that i want for the client that's it right so from here then actually i can get access to my clients uh directly yeah maybe actually this is client so if you want to use other service so let's say we want to use authentication service right for that we have another service client uh sorry account so you can create an instance of account so what you can do is you can create another member okay so let's actually do that yeah let's say we want to use databases yeah database that could be account no uh database will be database service database okay and we need to pass client so we need to initialize it inside init method so you can make it late database database so that we can say where the client is is in this client do you mean or different client that client okay so where should i initialize it like say you can make it late late final uh database yeah sure do you want to come to this page and actually take it over so that might be even easier so what we do here is we make it lit yeah so sorry database here you go yeah sure and then we don't initialize it here okay oh you initialized it when after the client is set yeah so all right okay sorry this is how we do it this i think you have github autopilot is it me or you i think me yeah yeah let me just turn it off this is globally okay so uh i think all right instead of this we might need to make it right so probably it's better yeah sure so we can't even make it final because we are initializing it later absolutely yeah so uh we can make it knowledgeable if we don't want it knowledgeable we can make it late and initialize it during factory so i tend to do that uh during the transformation okay sure okay let's have let's have a scenario here while we are actually initializing database maybe what we can do so if i actually click here there is a list of a very simple list of you know these copies okay so now these are actually hard-coded i want to actually move this to a table or like a column or whatever to have all of these copies in the database and read it from there maybe we can just implement that for get an understanding of how upright works and you know together with clutter do you think it's a good idea maybe we should start with authentication because without authentication we cannot write to database or even read aha okay we can read public resources but we can't read any but when you say authentication that means you mean that i definitely need to have like a login i'm not able to actually write database if if my user is anonymous no we can write with anonymous but we need to create an animus session at least so we have we need to have a session at least okay yeah all right let's do that then let's do that yeah let's so like database you can create account uh instance so there is account service so like i can just duplicate this and i can say account and here is going to be account yes okay and then and then same thing here yes same thing in the initialization yes exactly okay so in your login method uh we can create a login anonymous method or login method so that we can okay let's actually do it here login uh login like anonymous or something uh yeah anonymous yeah so it's anonymous we don't require any parameters sure okay so we can just call uh try cats we can try cats because uh we might get some exception right catch exception uh catch no on app right exception let me add this okay on yeah i okay you have like uh a specific exception is uh which is the app right right yes yes okay sounds good then uh for exception let's just do nothing for now no you can print yeah you can print but for okay what should i do in the try so a weight account dot but it this must be a sync then oh yes it must be a say a way to account dot create anonymous session okay oh here we go i do have a function for that but should i assign it somewhere like yeah you can you can assign it somewhere okay i think this is okay now it's fixed that was because uh the account it was null yeah cool so then i can say this is my account or or yeah this is a session uh this will get back a response uh my session yeah response dot data will be the actual session okay this is actually going to back like respond instead yeah so okay well i can see there is an annotation here response okay yeah and then should i this function should that return anything like or should it be just void um we don't need session actually if we are not planning to do anything with it at the moment because session is not the account uh session is just to uh initialize our sdk with cookies and everything so it's okay not only anything at the moment okay so then it's safe actually to just do this let's see yeah okay um okay i will make a comment here it's safe to just uh do this to create a new session yeah good so that's good um so probably then when i click on sign in right now i just need to call this function before that to complete the initialization we need one more thing so yeah yeah sure to prevent any client from connecting to our endpoint we need to add platform so you need to get actual uh bundler id we are in mac os right ios so we need the bundle id that you have for this project and we need to add it in our project in app right console okay all right so but then why do i need that but where should i pass that later so um why we need it is uh we need to add a platform and sdk handles it internally the sdk will send the package name while making the request as a origin so that uh the app right will trust the origin i see good okay then uh here is the service go ahead and do i'm gonna see what you do then so no uh what we need is we actually need uh the bundle id for this project can you uh but then i need to install the package for that like maybe package info so then i get my no we don't need to uh even hard code that is fine like i can copy and paste you mean yeah okay okay end it inside project dot pbx oh okay we are yes here we go yeah okay so yes let's let's do it again okay then to find the project bundle i did and i can maybe find it under my project uh ios file and here is actually the bundle id this is what you mean right the bundle identifier yes yes and the best way to get it would be to open the ios project in xcode and then get it yeah sure it's good so now we need to go back to our app right console dashboard and go back to home we are in settings back to home yes and scroll down scroll down right there is there is a button called add platform select flutter yeah tap on that and select flutter now here i can actually spawn the id yeah you can give any name meaningful name that you want to view there mj coffee app or ios and you need to register okay well technically i should do the same for android 2 right yes for me it's the same thing on the line yeah no you don't have to do it you can't do it in one go you need to do either ios or android in the first oh really yeah you need to but if it's one but if it's different then i need to register too right no you know we need to register multiple for each platform but we i think we can only do it one at a time oh okay okay i see i see you mean yeah first this and then come back and then add another one yeah if you need android one you can add another one as well yeah sure now i see um but right now we are running on ios only so it's okay to add ios for fun yeah okay good uh all right then uh then i'm good to go right let's go back to the code so okay uh let me open up my main again let me close this page oh here is my service so now we are uh ready right i can now just go and implement sign in for this method yes so i think the first thing i need to do is that in my main.dart i need to initialize my service so which is app right service yeah instance that this is what i need to make sure first of all in my application yeah okay now i have my uh everything ready so then i can go to my actually home page i think and that's going to be a login here actually i already said i want to implement a login action so this is uh what i'm going to do here then let's assume that it works right so i don't want to deal with cash and error handling and stuff like that but then let's get in service so it's good yeah but i know i know but i mean uh let's set uh i don't want to actually deal with if it's not like logged in or let's say there is no session or error just do not redirect show message let's not do that but this is something that we should take into account but then uh here i have my login anonymously uh why don't oh i need to import it yeah i do have my login announced okay so here is my there is an error here ah this is because it must be featured oh yes okay let's say that now it creates and then it redirects everything to my menu screen here is the safe um like we create vision let's uh for for everyone else let's add a to-do list to do um make sure error handling and proper logic will in place later yeah okay so good so here we go if i now actually maybe hot restart then if i log in then i will gonna i will uh all right so first of all i will see an error um missing plugin that's probably okay because oh no maybe it's not okay what is missing no implementation found for what actually let's see the message upright service uh package info uh you need to rebuild because uh upright package uses uh package info and device info to gather some uh information from any stuff like i need to stop completely and rebuild the game yes because by the way yeah you said that you're using package info and device info yes not the plus version plus version that's good i'm proud of you we are using the plus version because we support all platforms that's cool that's cool all right let's wait for the application to build okay and now it's building uh maybe we can take a time and go to the dashboard and create our database is that possible should i do that this is a database right we should create a collection so uh collector let's do that like a table in mariadb so we should create a collection name it may be coffee like i want my coffees yeah or create coffees okay yeah now i have a collection good yes i see this rule here so that i can actually specify rule per column or per collection right per table yes uh so we need to add columns so whatever columns you want uh you need to add those and update the collection before we can add any data we need a proper room okay all right so then now i have this uh that's good so i have the collection id here i see should i care about the permission at this point yes uh so in order for the user to be able to write in this collection we need to add some permission in write and uh to be able to read if we do not add any permission uh no data no one can read and write to this collection okay then i definitely want to write the maybe manually at the moment so but we we write the permission manually here so read access we can just say asterisk you can see add asterisk for wildcard access uh below okay yeah that's good now for right access let's say we want only logged in users to be able to write so you can say something like roll roll colon okay member no role called remember like that yeah yeah let's update let's just make sure there is no extra space in the permission right yeah i think it's good yeah sure uh okay good now let's let's copy the collection actually let's go back here okay it seems like it's uh coming up it's built already let me click remove this okay so now if i go to my sign in okay it seems now it's working so can i see in the dashboard can i see in okay where can i see that users yeah you should go to users you should see new anonymous user apps yeah here you go yes here we go there is actually all right good so now we have one person logged in yes um [Music] can i now just add or maybe okay let's uh let's actually add one of these uh coffee so i do have a coffee a model before we add so let's go to the coffee model we need to set up those rules because we need to know what columns is in the collection before we can add data well when you say rules do you mean rules in here dashboard yes okay you need to tap add and then label can be anything but let's keep the level and key same so okay so the label is like my my document label like like for example copy icon name price let's say name i want yeah name and price so name key name okay type text name might be text and you can hit create once you create we can create another let's say price that's going to enumerate yes numeric create uh another thing we can do uh just expand the name there is a expansion in name yes so okay if you scroll down you can make it required so name is required yeah it's not array that's fine we don't want default value that's fine do the same for price we can make it required for price yes and icon is icon data i don't think we can keep it here right yes it's icon data but don't worry about it that's okay let's just hit update once you set the rule uh you need to hit update here update button okay so we have our collection we have our rules right yes right and then like we this is the document okay yeah you can add document here you can add directly here if you try adding yeah let's do that let's let's say it's first so and prices and for example set the permission so that at least we can read oh for each document i need to set a permission it does not inherit from the collection yes at the moment the permission structure is like a bit difficult to understand because the collection uh permission only uh make sure that who can create new document or delete documents from the collection right so we are working on a new architecture in the new refactored database we'll have an option that will say collection level permission or document level permission right if we get that implemented we will only need to set up either collection level or document level uh not both so that is how we are planning to upgrade this let's see where it goes it's still under working okay sounds good so then write permission uh right for now nothing i don't want to change anything just keep yeah you can create okay okay well then i do have now one document here so now i have a question here so i do have a document i see the data yes so um then can i create another collection inside the collection this is possible in like firebase firestore for example right yes yes uh so i'm against it we can't uh right now we can do some sort of thing we have an embedded document if you go to the collection settings if you go to collection go to the settings tab and add rule try to add another so there is our rule type if you set the rule type there is one option called embedded document okay so let's say there is a history for this particular let's say things and then okay there is embedded here you mean yeah now that will basically embed the document from another collection so for that we need to create entirely another collection but i'm i'm against this because this doesn't serve any purpose right we can do the same thing just by adding id attribute to link each other so if i create another collection and link it with id it's good enough right you mean we can create a relation between our collections by adding an id to another collection like this is simply like uh let's say a relational database approach right we create tables and maybe one collection to have like to join different tables you know things like that for example no uh so we might think that uh that is not possible with app right at the moment like adding id will not automatically link but even without automatic link if we have the id we can actually fetch it from another collection right i see so right now if you use embedded document you can embed a collection itself it will be embedded as array of another collection or another documents or even single document from another collection but uh it's best not to add it uh it's best not i like i personally i don't like it uh because it complicates things even soft collection in firebase i don't use it that much i just create basically another collection and just keep a reference uh it's easier that way so uh it's i think with nosql it's fairly good to duplicate some data and not have like uh sub collections and stuff yeah yeah sure definitely well when it comes to duplication then there are come there are some things that might happen like for example how we can sync these data and you know some stuff like that but that's okay i mean one of the purpose of this uh nosql databases is to have uh this duplication to make it faster to query and receive your data you don't need to just go to different collections and stuff but i created that document reference in the um oh i think i forgot to update it let's say when actually let's say create logs let's say logs and then i'm gonna uh update it and then well once one thing that is okay now i have actually these logs here and that's gonna be uh empty uh it's empty because first we need to create another collection that is logs and then okay let's actually mock that let's say i have a log here yeah you can set a rule let's just add one rule let's make it like um yes let's say user that's a user id okay whatever it doesn't matter yeah okay yeah permission probably this um what should i do for the permission here like again role member or this is actually uh we can say role member yes for collection okay that's a quick quick one for the collection now i have logs collection and coffees collection so now if i go to cafes and we need to go to settings and link those up go to settings and if you expand this uh there is an option this is an array right we need multiple logs so you can turn on the array if you don't want multiple locks you can hide the array and then you can also check the logs collection there so this will be the embedded documents of logs i'm not sure if i well i'm trying to click uh there might be some issue with that i think we had a report regarding that let me try to log in but don't worry so yeah when i say array i'm not able to select but when i don't say array then i can select a collection maybe that's okay uh maybe you can just refresh the page and select it first array and then try to select it okay you mean that first update this yeah and now it's refreshed then open and then select it yeah okay so now i have actually my logs my logs is an array and a collection of logs that's good so then if i go back to my document here so i see the array you can probably find this document yeah you can uh i can i can okay add logs okay so whatever yeah and add so this will now consist of multiple logs but then where does these logs be stored like it will store in the collection of logs yeah okay there is a relation yeah okay so sounds good so now i have at least my database ready i want my price and name and the user is also ready that's the two most important services that i needed so let's go back here and you just help me to read the data i'm not going to actually change my app because i need to add more data i will do it afterwards probably but let's actually receive some data so how can i receive these data from database so let's make another function get coffees or something uh get coffees let's say yeah and we already have database service initialized yeah correct yeah we can use the same tri-cats as before just to be not gonna do anything okay yeah uh yeah try catch i like even similar things yeah exactly you can just copy past those things good yeah but then here probably i need to like call something on database right yes database dot list documents well let's let's take a look at this function so i have create document so probably i need to pass a collection id then i can create yes delete a document get a document list document and stuff okay the list document is what i want list of documents right yes yes so we need the collection id user uh you need to copy it from there uh it was this collection yes good so it's actually uh okay so that's no not yeah sure uh and then it's gonna be uh like is it respond again or is it coffees directly so a response it's response response.data will be the coffee list so it is actually if you print out response dot data let's print it so that we can see the actual response model or for each response we have extensive documentation if we go to our docs we can see what's what each endpoint responds as well i see okay so then um i'm gonna go now to my let's say menu page and then in the menu and like when i just i think i have a um initial state somewhere yeah i think i have an initial state do i no i don't but i can create an immediate state that's fine yeah um here we go and then here probably where i can actually call my app write service service and then i can have my instance and then get my copies yeah so then technically if i now refresh and then i go to my menu page i should see in the log the list of data let's see yeah let's restart but uh one question here that if i log in right now will it create like another session yes yes because we already have active session you can just check uh what we do to check active session is we try to get account dot uh get we try to call account.get okay so like in here you can have a future builder at the moment it's best to have like uh some kind of estate management but at the moment we can use a future builder yeah but uh how about like checking before even creating an announcement can i just say account dot here for example something no we don't need to do it here because we don't want uh each login call to check for account.get right we can have another another function uh get account function you can create another function called get account okay let's say here get account yes and then here account dot get yeah so here actually let's return true or false if there is an account let's return true otherwise let's return false and make future bulls but what what will it return is it it will return the actual account okay it returns an account so like uh okay let's say response account no it will return response response or return with the account and then respond that data if if it's not null right uh no uh if it's null it will go to the it will throw exception so account that get will throw exception if it doesn't show exception then we are logged in if it throws exception then we are not logged in so okay then it's safe here i say here for example true and here i say false yes and we can make future bull at the moment okay future bull for sure okay so in the login page or in your screen where you check whether or not user is logged in i was home page so here but then before that i can actually like do this like if can i do that here yeah like if that yet account get account yeah then we can simply navigate otherwise we can yeah so sure let's say if actually it's let me actually do this one here fine as account perhaps mission so then it has session it's actually if noah has session session create session otherwise just navigate okay that's technically what we do let's actually reassess if it works okay we can just confirm by going to app right dashboard and see if new user is created or not yeah okay i just clicked i'm gonna go to dashboard user no it didn't okay yeah so there is a question that's great so it's working yeah so then i actually now in my console i should see yeah i should see actually the data and here's the data i see it actually yeah so data is actually a list of documents that returns total number of documents that you have access in that collection so right now total number of documents is one and the documents filled in the data returns the actual documents list of documents i see okay so then here is where i need to now deserialize or you know create my dart object and maybe have all of my model and stuff like that and then render it so we're not going to do it today but that's uh that's good so at least we get some data so but uh to do once more so you said that the documents list is the list of document that i will receive and the id is the id of my document what is collection collection id it's basically collection id so for each document that is returning you also return the collection id yeah it's basically embedded in the document collection id and then and then we have the data which is uh this is the box this is actually locks another then uh this one here name is especially and price is 10. so yeah technically what we added and the logs is coming from logs table which we added already yeah you can see the collection id that is the logs collection id not the yes that's correct coffee all right very good so so far so great so i created my database i can add more copies and read from that that's perfect i assume that the writing is also not that hard so you showed me how i can add like the rules and for members and stuff like that i mean it's a lot probably to learn and read i i can understand but so far it's great and and i learned quite a lot i really enjoyed it the fact that i ran everything in my machine and i can actually host it somewhere later that's also a great opportunity yes so i think we should end uh our show go ahead if you want to say something yeah i have a couple of things one app right i o slash docs it's a great place so we have extensive documentation for each of our sdks if we go to app.ios stocks for each service so right now we are using account service so you can go to account service below in the rest api section yeah and we can choose the sdk right now there is web sdk you can choose flutter sdk there at the top you can see web sdk ah you went in another page not this one so in account service if you go to account service again so there is a choice web sdk you can see there client here uh yeah you can choose flutter sdk android sdk so if you choose flutter all the examples code examples will be flatter sdk yeah uh if you tap on any of the uh okay any of the requests there is example request and if you go below there is uh in the left hand side there is like this response for each service for each end point if you go little bit i see there is response right response object a bit scroll yeah so response yeah so each service has response this is request if you scroll a little bit down there is response yes here you go yeah and response uh this is not the one this is redirect try another one that has actual response so there is a response then there is a payload object if you tap on that you can see what each endpoint returns so how each end point returns i see okay that's cool so the documentation is also great yeah sorry i have one more thing sorry i have one more thing that is flutter sdk is uh adding another capability right now everything that flutter sdk returns is just plain uh json object that is map string dynamic right uh in the response data so right now we are going another iteration of flutter sdk where each endpoint will return the actual object so we'll have a dart object for account we'll have a dart object for like uh storage files everything and for documents we'll have something similar like firebase that you can convert to your custom model so you can get the document and convert to your custom model using the document endpoint so we'll have that response models implemented soon right now we are just retaining all the uh json object this is fantastic this is quite helpful actually so if you can't have everything in the code and just like play with that it's much better than just moving to the documentation website coming back again you know it just takes some time but it's great great improvement i am looking forward for the new um refactoring you know process that you are doing and also the new package for darth and mr flutter so this was great so far amidar so it was fantastic to have you on board and talking about uh app right well i learned personally i learned quite a lot i've never used app right this was my first time uh playing with that together with you and i'm gonna go and actually learn more about it definitely so i will probably rewrite my whole firebase app with uh upright and see get the feeling like how it works and that's fantastic but you should promise us maybe sometime later when you have the new refactoring in place new flutter sdk in place you should come back to this show and let's talk about the new features and everything that you amazingly have done and let us know and let us learn from you definitely so uh i have a couple of things i forgot before so one more thing we did not touch real-time api in this session uh but there is a real-time api from app right 0.10 uh which you can subscribe to real-time events so when a document is created or when new user is added you can you kind of subscribe to those things and you can get real-time notification using websocket server and then another thing we have is uh like sorry ah we have a server side sdks we touched only client-side sdks today right we were creating collection from upright dashboard right so we have a server-side sdk even for that we have that upright sdk using which you can do all those things that you did from console using the code so you can create collections you can create like users you can create anything from the server side sdk using the api keys so that is also another possibility that's fantastic i cannot wait to play with these features so i will definitely go ahead and do and maybe create some more videos or articles around it perfect thank you very much perfect thank you very much it was great to see you in this show if you have anything else to share please do otherwise then let's actually before we finish let me quickly open up our your sdk website on github yes here is the here's the sdk for flutter everyone can see first of all shame on me i didn't star you i just did thank you so and uh here is uh the whole sdk i think uh the mudar and the team will appreciate your contribution so please go ahead to this repository and make issues and also send requests for requests that would be fantastic let's get this amazing open source moving forward and with perfect anything else that you want to share with us uh uh nothing so i just want to thank you for having me in this show and giving upright uh a place to share this i'm really thankful from myself and from the whole upright team that you get gave us this opportunity i hope uh many people will join app right after seeing this we hope to see a lot of new people and we always love community and contributions because we are open source we work in open you can see all our pull requests we you can see all our issues that we are working on what's going on what's coming next so uh come join us you can join us on our app right discord it will be upright io slash discord so come hang out with us you can learn anything our discord is quite active if you have any issues i urge you to join discord as well and or all everyone listening to this to join our discord so that we can learn together and we can create something awesome together fantastic i will put all the links in the show note or the comment below and everyone can later click and just go and join this amazing community thank you very much once more than with her and with that said have a fantastic lovely day thank you you too [Applause] you
Info
Channel: Majid Hajian
Views: 478
Rating: 5 out of 5
Keywords:
Id: UkEppuU5yF8
Channel Id: undefined
Length: 70min 49sec (4249 seconds)
Published: Wed Oct 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.