Coder Social home page Coder Social logo

pyhoon / miniormutils-b4x Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 80 KB

A mini object–relational mapping (ORM) that can be use for creating db schema and SQL queries.

License: Creative Commons Zero v1.0 Universal

VBA 24.29% Visual Basic 6.0 75.71%
api b4j b4x database orm schema sql sqlite table web

miniormutils-b4x's Introduction

MiniORMUtils-B4X

Version: 1.13

A mini object–relational mapping (ORM) that can be use for creating db schema and SQL queries. It is suitable for Web API Template or any database system. Currently it supports SQLite and MySQL (B4J).

Usage example

Initialize object

Dim MDB As MiniORM
MDB.Initialize(Main.DBOpen, Main.DBEngine)
MDB.UseTimestamps = True
MDB.AddAfterCreate = True
MDB.AddAfterInsert = True

Note: Before calling MDB.Create and MDB.Insert, set AddAfterCreate and AddAfterInsert to True.

Create table

MDB.Table = "tbl_category"
MDB.Columns.Add(MDB.CreateORMColumn2(CreateMap("Name": "category_name")))
MDB.Create

Insert rows

MDB.Columns = Array("category_name")
MDB.Parameters = Array As String("Hardwares")
MDB.Insert
MDB.Parameters = Array As String("Toys")
MDB.Insert

Execute NonQuery Batch

Wait For (MDB.ExecuteBatch) Complete (Success As Boolean)
If Success Then
    Log("Database is created successfully!")
Else
    Log("Database creation failed!")
End If
MDB.Close

Select All Rows

MDB.Table = "tbl_category"
MDB.Query
Dim Items As List = MDB.Results

Update row

MDB.Table = "tbl_products"
MDB.Columns = Array("category_id", "product_code", "product_name", "product_price")
MDB.Parameters = Array As String(Category_Id, Product_Code, Product_Name, Product_Price)
MDB.Save

Soft delete row

MDB.Id = 3
MDB.SoftDelete

Permanent delete row

MDB.Id = 4
MDB.Delete

Batch delete rows

MDB.Destroy(Array As Int(2, 3))

Return number of rows in query results

Dim Rows As Int = MDB.RowCount

Return single row

Dim Data As Map = MDB.Find(2)

Return multiple rows

MDB.Table = "tbl_products"
MDB.Where = Array("category_id = ?")
MDB.Parameters = Array As String(2)
MDB.OrderBy = CreateMap("id": "DESC")
MDB.Query
Dim Data As List = MDB.Results

Join tables

MDB.Table = "tbl_products p"
MDB.Select = Array("p.*", "c.category_name")
MDB.Join = MDB.CreateORMJoin("tbl_category c", "p.category_id = c.id", "")
MDB.setWhereValue(Array("c.id = ?"), Array(CategoryId))
MDB.Query
Dim Data As List = MDB.Results

miniormutils-b4x's People

Contributors

pyhoon avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.