πΎ AppML β Local Storage & WebSQL Support: Create Offline-Ready Web Apps
π§² Introduction β Why Use Local Storage and WebSQL with AppML?
AppML allows developers to build fully functional, data-driven web applications using only HTML and JSON. By integrating Local Storage and WebSQL, AppML apps can store data offline, maintain state, and even perform CRUD operations without a live serverβperfect for static hosting, offline apps, and educational projects.
π― In this guide, youβll learn:
- How AppML uses
localStorage
and WebSQL - How to store and retrieve data offline
- How to define local AppML models and sync them
- How to use forms and views with client-side databases
ποΈ What Is Local Storage in AppML?
Local Storage is a built-in browser feature that allows you to store key-value pairs on the client side. AppML can use localStorage
to store JSON objects directly.
β Use Cases:
- Saving app state or preferences
- Storing user form inputs offline
- Retaining records without a backend
π₯οΈ Example β Store Form Data in Local Storage
<div
appml-model="models/contact-model.json"
appml-data="local:contacts"
appml-message>
<h2>Offline Contact Form</h2>
<input name="name" placeholder="Name">
<input name="email" placeholder="Email">
<textarea name="message" placeholder="Message"></textarea>
<button appml-submit>Save Locally</button>
</div>
π Explanation:
appml-data="local:contacts"
stores the data intolocalStorage.contacts
- Data persists even if you reload the page
- No server connection is needed
π Model β models/contact-model.json
{
"key": "id",
"fields": [
{ "name": "name", "required": true },
{ "name": "email", "required": true },
{ "name": "message", "required": true }
]
}
π This ensures all fields are filled before submission using AppML validation.
π½ What Is WebSQL and How Does AppML Use It?
WebSQL is a browser feature (now deprecated in most modern browsers except older versions of Chrome and Android) that lets you store and query data using SQL commands inside the browser.
β Use Cases:
- Building data-heavy offline apps
- Creating client-side databases for temporary storage
- Teaching SQL concepts in the browser
β οΈ WebSQL Browser Compatibility
Browser | Support Status |
---|---|
Chrome | β Deprecated |
Safari | β Supported |
Opera (old) | β Supported |
Firefox/Edge | β Not supported |
If you need long-term offline support, use IndexedDB or Local Storage instead.
π₯οΈ Example β AppML Using WebSQL (Only in supported browsers)
<div
appml-model="models/products-model.json"
appml-data="websql:products"
appml-message>
<h2>Local Inventory (WebSQL)</h2>
<p>{{name}} β ${{price}}</p>
<input name="name" placeholder="Product Name">
<input name="price" type="number" placeholder="Price">
<button appml-submit>Add Product</button>
</div>
π Explanation:
appml-data="websql:products"
stores and queries data from a local SQL table namedproducts
- Works like a mini-database inside your browser
- Great for app demos or learning SQL on the frontend
π WebSQL Model β models/products-model.json
{
"key": "id",
"fields": [
{ "name": "name", "required": true },
{ "name": "price", "datatype": "number" }
]
}
π Sync Local Storage With Remote Data (Hybrid Use)
AppML supports fallback loading:
<div
appml-data="local:contacts;data/contacts.json"
appml-model="models/contact-model.json">
</div>
π What this means:
- First tries to load data from
localStorage.contacts
- If not found, falls back to loading
data/contacts.json
from server
This helps you create offline-first apps that later sync with the cloud.
π§ Best Practices β Working with AppML Local Storage
β Tip | π Why It Helps |
---|---|
Use local: for offline-only apps | Fully functional without a server |
Store form data in local: keys | Simplifies development and saves drafts |
Test WebSQL in Safari or legacy Chrome | Ensure compatibility before production |
Combine local + remote fallback | Enables both offline and online modes |
π Summary β Recap & Key Takeaways
AppML lets you build full offline applications using localStorage and WebSQL with zero JavaScript and no server dependency. Whether you’re creating a form, an inventory app, or a data grid, AppML makes storing and retrieving data in the browser easy and reliable.
π Key Takeaways:
- Use
appml-data="local:key"
to bind data to browser storage - Use
appml-data="websql:table"
to interact with a local SQL database - Combine
local:
with fallback server data for hybrid apps - Model-based validation ensures data consistency
- Works great for low-code, offline-first applications
βοΈ Perfect for PWA prototypes, static hosting, student projects, and internal tools.
β FAQs β Local Storage & WebSQL in AppML
β Is AppML compatible with IndexedDB?
β Not directly. AppML supports only localStorage
and WebSQL at this time.
β Does WebSQL require a server?
β
No. Itβs a local feature. But WebSQL support is limited to specific browsers.
β How do I clear AppML local data?
β
Use localStorage.removeItem("key")
in your browser console or script.
β Can I sync local data back to the server?
β
Yes, but you must write a controller or server-side sync handler manually.
β What happens if local storage is full?
β οΈ Browsers usually allocate 5β10 MB for localStorage. If exceeded, it will silently fail.
Share Now :