Giter Site home page Giter Site logo

as3query's Introduction

As3Query

Another SQLite ORM and query DSL for Flex and Adobe Air

Uses Promises/A+ library.

Annotations list:

  • Specify table name [Table(name="test")]
  • Specify table index (or multiple indices) [Index(name="test_index_1", columns="unsigned,bool", unique="true")]
  • Specify table column [Column(primaryKey, nullable="false", unique="true", foreignKey="table(id)", options="deferred", default="1")]

Usage:

  1. Put annotations:

        [Table(name="test")]
        [Index(name="test_index_1", columns="unsigned,bool")]
        [Index(name="test_index_2", columns="str", unique="true")]
        public dynamic class TestEntity
        {
            [Column(primaryKey, nullable="false")]
            public var id:int;
    
            [Column(default="1")]
            public var unsigned:uint;
    
            [Column(unique="true")]
            public var date:Date;
    
            [Column]
            public var xml:XML;
    
            [Column]
            public var xmlList:XMLList;
    
            [Column]
            public var object:Object;
    
            [Column]
            public var bool:Boolean;
    
            [Column]
            public var num:Number;
    
            [Column]
            public var str:String;
    
            [Column(foreignKey="table(id)", options="deferred")]
            public var fk_table:int;
        }
  2. Map entity:

        var entityManager:EntityMapper = new EntityMapper();
        entityManager.registerEntity(TestEntity);
  3. Create tables:

         var connection:SQLConnection = new SQLConnection();
         connection.open(file, SQLMode.CREATE);
         try
         {
            new CreateTables(connection, [TestEntity], mapper).call();
         }
         finally
         {
             if(connection.connected)
             {
                 connection.close();
             }
         }
  4. Create session:

        var session:Session = new Session(mapper);
        session.open(file.nativePath, SQLMode.UPDATE).then(function ():void{ trace('ok') });
  5. Perform different operations:

    Criteria

        session.criteria(TestEntity).by(Order.asc(TestEntity.ATTR_ID)).list.then(function (operation:ISQLOperation):void{ 
            trace(operation.result); 
        });
        session.criteria(TestEntity).when(Restrictions.Eq(TestEntity.ATTR_ID, 1)).unique.then(function (operation:ISQLOperation):void{ 
            trace(operation.result); 
        });
        session.criteria(TestEntity).when(Restrictions.Eq(TestEntity.ATTR_ID, 1)).count.then(function (count:int):void{ 
            trace(count); 
        });

    Create, update

        session.save(testCriteriaEntity1).then(function ():void{ trace('ok') });

    Delete

        session.remove(testCriteriaEntity1).then(function ():void{ trace('ok') });

    Transactions

        var transaction:ITransaction = session.transaction;
    
        transaction.insert(testCriteriaEntity1);
        transaction.insert(testCriteriaEntity2);
        transaction.remove(testCriteriaEntity2);
        
        transaction.run.then(function (operation:ISQLOperation):void{ 
            trace('ok'); 
        });

    Raw queries

       var query:IQuery = session.query;
       query.text = "update test set str=:str where str=:id";
       query.parameters[":id"] = "inserted2";
       query.parameters[":str"] = "inserted3";
       query.run.then(function (operation:ISQLOperation):void{ 
            trace('ok'); 
       });

You can add metadata validation to Intellij Idea using KnownMetaData.dtd file. Open Preferences > Schemas and DTDs > Add KnownMetaData.dtd with URI urn:Flex:Meta

as3query's People

Contributors

kemsky avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mobitile

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.