Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6346405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:00:40+00:00 2026-05-24T21:00:40+00:00

I am going to start doing a couple of Adobe AIR projects that will

  • 0

I am going to start doing a couple of Adobe AIR projects that will be using SQLite feature provided by AIR. Since this is the first time I am attempting to do this, I would appreciate some pointers, tips and Best Practices for development.

Since this application will be accessing a local db, I think I can open a connection to the database at the start of the app and keep it open till the application closes. Is this a right approach to use here?

How should design my application if I am using an MVC framework like Mate or Cairngorm?

Should I create some wrapper class to perform the db operations so I can reuse this in some other project? Looking forward to some valuable information…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:00:40+00:00Added an answer on May 24, 2026 at 9:00 pm

    The first and by far most important decision you have to make, is whether you’re going to access that database synchronously or asynchronously. They both have their pros and cons, so it will depend on your situation.

    Synchronous

    • simpler architecture
    • easier to read
    • better suited for small operations
    • freezes the app while doing the operations

    Good for small scale app

    Asynchronous

    • more complex architecture
    • harder to read
    • long operations will not freeze the UI
    • if you have to sync with a server DB, you can create an interface for both local and remote DB services (e.g. the class LocalUserService and RemoteUserService both implement an interface that forces them to have a method saveUser())

    Good for larger scale app and synchronizing local and remote data.

    I tend to almost always opt for the asynchronous approach – since it’s more flexible – and abstract the complexity away in … a wrapper class. So that answers that part of your question.

    Architecture

    I don’t like frameworks, so I can’t answer your question about Mate or -shudder- Cairngorm. But here’s what I consider a fairly good approach:

    • for each entity in your model, create a Data Acces Object (DAO) that will return only raw query results (e.g. UserDAO for quering Users). That class should contain only queries.
    • matching each DAO create a Builder/Factory that can take those query results and spawn model objects (e.g. UserBuilder)
    • this is usually enough for me, but you could also bring the two of them together in a service layer (e.g. UserService). This service layer might also help matching an existing remote service layer to your local services.

    As for keeping the connection open. I’ve always done so and never had any issues with it. I don’t exactly know what happens when an application crashes and the connection wasn’t properly closed, but this is not Oracle or SQL Server we’re talking about. I don’t think SQLite will keep open pointers or something since it’s just a simple file, but I might be wrong.

    Edit: some more details on the DAO / Factory pattern (as requested by OP).

    An example of a UserDAO with one function:

    public class PupilDAO extends AsynchronousDAO {
    
        public function getUserById(id:int, handleResult:Function):Responder {
            return getResults(
                "SELECT * FROM user WHERE user_id = ?", 
                handleResult, [id]
            );
        }
    
    }
    

    As you can see, I’ve abstracted out the complexity into the AsynchronousDAO base class, so we can see only the necessary information in UserDAO. The handleResult function is a callback that will be called whenever the query is ready, passing in the resultset as an argument. We’ll usually pass that resultset into the factory/builder class.

    An example of a UserBuilder:

    public class UserBuilder {
    
        public function buildUser(record:*):User {
            var user:User = new User();
            user.id = record.user_id;
            user.firstname = record.firstname;
            user.lastname = record.lastname;
            return user;
        }
    
    }
    

    This is obviously a simple example, but you can create more complex data structures in the builder. For some info on the difference between the Factory and Builder patterns I recommend Google.

    Now let’s tie it together in the service class:

    public class UserService {
        private var dao:UsetDAO;
        private var builder:UserBuilder;
    
        public UserService(dao:UserDAO, builder:UserBuilder) {
            this.dao = dao;
            this.builder = builder;
        }
    
        public function getUserById(id:int, handleResult):void {
            var handleResultSet:Function = function(resultSet:SQLResult):void {
                var user:User = builder.buildUser(resultSet.data[0]);
                if (handleResult!= null) handleResult(user);
            }
    
            dao.getUserById(id, handleResultSet);            
        }
    
    }
    

    Finally, let’s put the trio to use:

    var userService = new UserService(new UserDAO(), new UserBuilder());
    userService.getUserById(1, handleUser);
    
    function handleUser(user:User):void {
        trace(user);
    }
    

    For the example I constructed the classes with new and passed the dao and the builder as constructor arguments, but you could use injection or singletons or whatever framework you like to do the construction for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is one of those I'm going to start doing something new because I
I was going to start using === (triple equals, strict comparison) all the time
I am going to start working on a website that has already been built
We are going to start a long lasting project using C++ as the programming
I'm going to start working on project developed in ASP.NET. In this project I
I am going to start a project of my own, which will be ASP.NET
I'm going to start a new project that's building web apps from scratch. I
i see a couple of questions on here and elsewhere that address this in
I'm trying to build an application using AIR 2's new NativeProcess API's going from
i am thinking of doing a start up menu before going into the real

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.