i'm using angular13 with electron , i'm stack with one problem , i have to store data in local system and get that data and perform curd on that data - electron

I am building a desktop application using Angular 13. to build the desktop application I am using electron JS along with Angular 13. here I've requirement to store a data in the local system.
So I need your help like which process I need to follow to store the data in the local system. also I want to display a data inside application in a list format.
Right now i'm doing but facing an issue, please review below details I have 1 JSON files on the client-side which are basically an array of JSON objects, from where I read and use in my component. I want to add (or edit) an object in those JSON files using angular only(without sending it to backend) and then make sure component is able to use it. Is it possible through angular? Or will I have to use a typescript file and store all information there?
I need to store the data inside the operating system as the data will be in large amount
Please if there is any other way that we can store this data in local system and show it in the application then please help me.
I have this form add form
and store this form data in local(os), get that data in listing page list form data,
and able to do curd on listing page ,
Thanks an advance
can't use backend apis

Related

App structure iOS and Realm: create database when app is installed

I am very new to iOS. I am developing an app with data persistence. I have decided to use Realm for that purpose.
I must to create the database and load data the first time that app runs. I get data from a Web Service in JSON format. I will implement some strategy to update this database later, maybe with iOS Silent Push notifications.
I have read and I have worked about Realm, loading data from JSON... to learn about that.
Now, I need to apply this in my project but I don't know how to start. I need some clues about general idea for the app:
How can I organize my app to load data when it is installed? At what point should I create the database and load data?
I have thought to create a global Realm object y AppDelegate and use it as a global variable. Is it a good idea?
Do I need to set a path for my database? Can I user default path?
If you are looking for a place to start, you can check out the example apps of this UI component add-on for Realm: ABFRealmGridController.
The controller is a subclass of UICollectionView and the example app should demonstrate most of the functionality you are curious about. The example uses the controller to display the top news stories from the New York Times. This involves making a request to their API and loading the JSON response data into Realm.
When to load the data is dependent on how you want the app to function. If the data will be the same for each user, you could bundle the Realm file with the app pre-populated with data.
The ABFRealmGridController example loads data when the user clicks the refresh button and performs the JSON handling on a background thread; a general best-practice.
Finally, unless you have multiple Realms or need to store the file in a specific path, it is probably simplest to use the default path.

Best way to check for data updates on webserver

I have an application which uses the data from web server. When you first launch the app, it downloads the data and then work with it. But what if the data on web site was changed. How can I know from the application that the data was changed, and if so, what data should I download?
My first idea was each time when you run the application to check the number of entries in the local database on your phone and the number of entries on web server, and if they are not equal, delete all data in local database and then download all data again. But I think that it will take more time than if the application just loads 5-10 needed records instead of all data.
The second idea was when the information on the site changes, website somehow has to inform the application to load some records. But I don’t know if it is possible to do(
Another idea was to compare the id of the last entry in the application database with last id on website. And if they are not equal download the information from the next id.
Are there any suggestions how can I accomplish this?
I am not sure that you have any database or web services but my suggestion is parsing data from the web with JSON or XML.
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/
this class reference is will be clear for you.
Also in my opinion, if you are new in swift and want to choose easy way for this operation search for iOS package managers.
If you want to use a package manager for your project, e.g Pod
https://cocoapods.org/pods/Alamofire
would be a good startig point.
Alamofire is an HTTP networking library written in Swift.
Hope to helped you

Where to store user settings in Electron (Atom Shell) Application?

I can't seem to locate a built in mechanism to store user settings. I was hoping that electron provided a standard method for storing user settings across all desktop platforms. If there isn't a precedent for this I can implement it myself, I just didn't want to jump to a custom solution immediately. Research online is pretty sparse in this area. Thanks!
Each platform has different default locations for different kinds of data. So, if you want to store data in default locations based on platform, check out app.getPath(name)
It retrieves a path to a special directory or file associated with name.
You can also use it to differentiate between data the user wants to save, and data your application saves that you don't want to clutter up users directories.
Or if you just want to store files reletive to a specific path you can use the
app.setPath(name,path)
I've faced this particular problem with my Electron app and this post inspired me to write an NPM module called electron-json-storage.
This module allows to easily write/read JSON to/from app.getPath('userData'):
const storage = require('electron-json-storage');
// Write
storage.set('foobar', { foo: 'bar' }).then(function() {
// Read
storage.get('foobar').then(function(object) {
console.log(object.foo);
// will print "bar"
});
});
Electron doesn't give you anything out of the box for this. However, Electron does give you a method for getting the idiomatic location of storing user data in a cross platform way via the app.getPath API.
I'd say the 3 most common ways to do this are:
localStorage (or any HTML5 storage API)
flat JSON file (this is what I do, and I use electron-store for it)
embedded database like IndexedDB, neDB, or sqlite
Which one you choose will depend on your app's needs. If you only need to access this data in the renderer process, then I'd just use localStorage. Most of the time it seems you need to access the data in both the main and renderer, so a JSON file makes sense. If you're dealing with lots of data or complex querying, then maybe a database makes sense. I wrote about this more in detail here.
How about LocalStorage? If you need to access these settings from the browser process, you probably need to write your own (or just use a node.js library that implements this)
The best way that I have found is to store it in a simple file as JSON. The problem is that if you store that JSON in the app dir, then when you update the app, it will get wiped out. So you want to put it in the default directory for user settings for the current operating system. LUCKILY!!!!! There is a library for node developers that will help you find the userdata directory. The module is called appdirectory, and I have used it several times. It is extremely easy to use.
See APPDIRECTORY HERE
One could store data in cookies; Electron has a mechanism for it (https://electronjs.org/docs/api/cookies) and the cookies can be retrieved in the browser (Angular: https://docs.angularjs.org/api/ngCookies/service/$cookies, React/Other: https://github.com/reactivestack/cookies)
I was able to get it working with Angularjs.

CouchDB and iOS

I need some help with a CouchDB iOS project.
I'm using Apache CouchDB Server and the couchbase-lite iOS Framework.
On my CouchDB I have a template document.
- CouchDB Server
- database
- template
- document 1
- document 2
- ...
My goal is to only synchronise my iPad with this template document to get the latest data which my application needs.
But when I enter some data on my iPad, I want that this data should be pushed only to couchBase Server.
How can I "tell" my application to synchronise only one file and not the entire database with my server and at the end how can I "tell" my application to only push the data that is input from user side ?
More importantly, Do I need two databases on my server? One for the template and a second one for user input data?
If YES, then I just need to know how I can only push my data.
Guidance needed. Thanks.
This is how I solve this:
I tend to add a 'last update' date to all my documents, and store this in a format that means they'll be sorted in time order (epoch or yyymmddhhmmss) both do.
Create a view that uses the update time as a date.
On your client, store the time since you last updated.
When you update, access the view with a startkey parameter set to the last update date.
You can then either use 'include-docs=true' to get the documents as you query the view.
I tend to use 'include-docs=false' though as it means when a lot of documents have been updated I transfer less data in a single query. I then just directly access each document id that the view returns.

Storing data locally or just using ajax on mobile devices? - appcelerator

Currently I'm building a few mobile apps (currently on iOS but later on Android)that retrieve information via ajax calls (returning JSON) from a Ruby on Rails application. This obviously applies to other applications as well that are using another source to return the JSON data.
The main question is WHEN to store the data and when to just use ajax calls to retrieve it. Currently, my apps do not store a single thing locally and instead require ajax calls for all data. I think for this example we can use the Twitter mobile app, which is one a lot of people are familiar with and has a lot of functionality that I'm wondering how they do it (more logically than technically).
Questions:
1) When you log in the first thing you see is a list of all of the items in your stream. That list is available offline. Does that mean that when you originally signed in, Twitter already went and pulled all of your last X (100?) stream items into a local database and then future views just pull it from there?
2) If you then put your phone on airplane mode (or just shut off mobile data) and click one of those tweets, it opens up the tweet page with all of that data. So now, it looks like they aren't pulling that information in via individually each time you visit a tweet page (which is what my app currently does and takes some time to load that data in and create the views). Does it make sense that they are probably just using the same information that they pulled in when creating your stream items?
3) Users. Is it better practice to (when viewing a users "profile" page for example) store a users data locally and then refresh on future visits, or just do pull in all of the data via ajax each time? In theory each requires an ajax call...
I think those are my main questions for now. If anyone has any thoughts on any of those things (or any other insights into mobile storage) that would be great! If anyone needs screenshots of anything I referenced please let me know and I'd be happy to get those for you.
Currently using:
Titanium Appcelerator for iOS
Ruby on Rails for Backend and remote storage
Ok firstly there is a difference between local storage and device cache.
Mobile phones cache a lot of data so that it doesn't have to be requested each time using up your data plans. Its the same idea when you open a page on safari, go to home screen and go back into safari its still there. This wasn't saved locally its just been cached by IOS.
When you should use local storage is when the data never changes, using twitter as an example like you have, on first start up it downloads your current activity, if one of those contains a link then it will generate a new request, if you have turned off cellular data and still been able to click a link, this is not because twitter has stored it locally but because IOS has cached it temporarily to avoid downloading multiple times. twitter may very well store some of you activity locally, but at least from what I've seen it stores a maximum limit of them starting with most recent, it downloads the rest frequently.
generally speaking if the data is based on the web its fine to use ajax calls, that is what most do, local storage is when the data is only created / viewed on the device (like an app for taking down notes). If you wish to provide local storage so that someone can view there activity offline, great but this is a feature not a requirement.
Most people would only start thinking about this if users frequently request the same data over and over and its not going to change often, then you would need to develop a last modified system, where you send an ajax call to see is there anything new, if not read from local. If the data is dynamic and subject to change often, stick with the ajax calls

Resources