create json with data local - flutter

Good morning, community, I would like you to help me with a topic that has me confused, going into context: there is a project in flutter which consumes an api that must be stored locally to avoid making requests to the webService. The serious question is how can I consume the data from my local database to create the corresponding widgets and thus create the respective forms?
I have tried to make a query for each table saved in my local database and there create a json and consume it,
however this has a disadvantage which when traversing each table takes time and in performs it is not optimal

Since you're using Sqlfite package you can use this site Dart QuickType to generate your models to import your tables from the local storage, I suggest make a single class handling the DB access, and then as many as you need (models and DAOs in where you write your queries) according to your DB arch.
You can consume later your info using FutureBuilder or StreamBuilder if you're using BLoC architecture or another DB management package like drift

Related

Flutter - Is it necessary to use Model class in Flutter?

Is Model class a must have for flutter application? If so, where is it comes into the picture in a simple database fetch, insert, update scenario? I am using supabase for my application. Can't I fetch data from database table and display in a page (I am using Provider for State Management)? Similarly, can't I insert data by directly reading from widgets?
It's not necessarily a must have and there are always work arounds, however it could save you a lot of code because you'll be repeating yourself often without it, especially if you're making a bunch of API calls and you need to serialize the data to a JSON readable format.
If you fetch it from your database I assume it'll be in a JSON format, from which you'll have to deserialize it. Personally, I think your project will be much easier with models classes.
There are plenty of extensions that can help you with this. For example, search for Dart Data Class Generator.

Postgresql in Node-red

I use node-red to create an Api from a server. I want to read and send data via http. I use the browser-based programming method. I want to send data from a postgresql database. I installed the package node-red-contrib-postgres-multi. I don´t know how to put data into the database and how to read data from the database, because I cannot find examples.
Does anybody knows, how I can do that?
You can use postgrestor postgrestor package where you can define query or data modification statement directly in node window. It also allows parametrized queries via template engine.
The problem I've encountered is working with more than one db instance in the same flow but if you need only one db instance connection it should work for you.

What is the most lightweight way to get last modified datetime from an Aqueduct application?

I'm writing a very small REST API using Dart/Aqueduct hosted on Heroku utilizing PostgreSQL.
When communicating with this API, I need to fetch all data and store it in an application locally. The application will on reboot ask the API if any data has changed in any databases, which will only get modified through this API.
My question is: How do I check, whether data has been modified? Storing it in the Aqueduct channel is not viable, as Heroku will boot servers up as needed (and multiple at the same time) changing this modified date time each time.
PostgreSQL cannot supply this modified date time (https://dba.stackexchange.com/questions/58214/getting-last-modification-date-of-a-postgresql-database-table) - so what do I do? Is the only way to do this to have a seperate table storing this information? Can this be done more lightweight, so I wouldn't have to make a query to the databases when e.g. calling https://my-api.com/lastModified? Should I serve a static file, which should be written to on each data modification?
Maybe there exist a smart, lightweight solution!
Cheers :)
Yes, use a separate table to store the date - the ORM is already doing this to track migrations. I’m not sure what light weight means in this context, but you won’t run into any problems with this approach, whereas a file or in-memory storage won’t work at all.

how to create a database that is suitable for xcode?

I have understood the basic concepts of core data and how to create schemas or data model in xcode. However I am struggling to create database and import it xcode.
I don't have any experience with creating databases before.
Can somebody guide me here.
Thanks in advance!
If your application is document based, the database is the document. You create it in code when you create the document.
If it's not document based and will use just one single database, then you generally create it in code the first time the application is run (or, more likely, whenever the application is started and it cannot find an already existing database).
In either case if the database can start empty, that's all you need. If an empty database would be invalid and you do need some minimal data when you initialize it, you will have to populate it upon creation.
Depending on how much data your minimal database needs to have you can either hardcode the initialization or use a static resource (that is, a file) in your application bundle containing the initialization data in some form that you know how to read and use that to populate the database.
Using SqlLite is more attractive to me as I import the database without any modifications to the android version.
And I made some generic class to handle any database for android and iPhone but I cannot share it here.
Class DBWRAPPER
{
initDB();
ExecuteScalar()
ExecuteDicionary();
Close();
}
To follow-up on the AnalogFile answer, in case your application is not document base, you probably want to use core data with a preexisting SQLite DB. You could feed your DB with a scripting language like Python. e.g. I think it is a better approach than populating your DB programmatically in XCode. Check this tutorial for more info about this approach.

RavenDB and Inserting data

I recently started using RavenDb. I am converting a relational dbase to use RavenDb. I have two simple tables in the Relational dbase:
tbStates
tbCities
I have all US cities linked to a state. How can I go about converting this to no-sql. Will I have to write a little application to read from the relational dbase and create the objects? Or are there some tools out there I can use to do this?
There is a utility called smuger http://ravendb.net/documentation/smuggler but I imagine you will have to convert your data to Json. It may be just as easy to write a console app that reads the tables to objects then loads to Raven.
Just to add I migrated a SQL Server database to RavenDB using the console application route.
I used EF to quickly pull out the data and converted it to my RavenDB domain then added it to RavenDB.
It Worked well as you will most likely want to tweak the domain anyway to work best with RavenDB (For example I had an Images SQL table that I turned into a List on the document etc).
See Ayende's RacoonBlog project on github (https://github.com/ayende/RaccoonBlog) as he does something similar to move subtext data to RavenDB. RacoonBlog is the engine powering his blog and makes for good learning material about how to use RavenDB.