Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Server] ORM
#1
ORM build for Gothic 2 Online

works with: MySql Module(V.0.3)

Test version! 
(Be aware that it's not been tested in real environment)


Link to file

!Report Error here

Script contains 4 main elements
- Active Record with control ur model creation save/modify
- Connector with is simples of all. Allows to create connection with database.
- Builder starting from phrase Query() with allows user to create most of operation simply by using functions builded in.
- Migration module allows user to create sql queries only one time.

Active Record

Build in base of query builder use some of features to controll proces of creating new model and update him. Allows also to easy find and use models base on table. Contains also some function to control rules for fields in table. (Validation). With this model you can easily create e.g. Player class or House.

Connector

Contain simple function to build query like queryGetAll, queryGet and some basics stuff to operate on Database. Build on Class you can directly use 2 databases in same time. 
If u dont wanna use Builder/Active Record u should use basiclly just this class to controll your connection and quer'ies.

Code:
local db = Connector(host, user, pass, db, port);
db.queryGetAll @return {array}
db.queryGet @return {array}
db.getDatabaseSchema @return {array}
db.query @return {bool}
db.check @return {bool}

example
DB <- Connector("localhost", "root", "", "gothic", 3306);
DB.query("CREATE TABLE `test` (person int(11));");


Builder

Builder allows user to create query command simply by use builded functions. (Fast way to create query). Remember to have on mind that is only alpha version. I need to build more functions.

Code:
local query = Query();
query.getSQL @return {string};
query.execute @return {bool};
query.all @return {array};
query.one @return {array};
query.where @return {obj};
query.from @return {obj};
query.update @return {obj};
query.orderBy @return {obj};
query.createTable @return {obj};
query.insertInto @return {obj};
query.deleteFrom @return {obj};
query.primaryKey @return {obj};
query.dropTable @return {obj};

Query().select().from("player").where(["id = 1", "name = 'Quarchodron'"]).one();
Query().deleteFrom("player").where(["name = 'Jacek'"]).execute();
Query().insertInto("player", ["name", "password"], ["'Jacek'", "'Warnenczyk'"]).execute();
Query().update("player", ["name", "password"], ["'Jacek'","'Warnpozmianie'"]).where(["name = 'Jacek'"]).execute();


Migration 

Simple class contain controll of creating new table / inserts or just changes in database. Changes is saved in table 'migrations' with allows to not build same changes twice.

Code:
local mig = Migration();
mig.run();
mig.down();

// Installation
class TestMigration extends Migration
{
    // need to use this to create row in table 'migrations'
    static nameMigration = "PlayerMigration";

    // Create run up function base on builder
    function runUp() {
        Query().createTable("character",[
            ["id int NOT NULL AUTO_INCREMENT PRIMARY KEY"],
            ["name varchar(255) NOT NULL"],
            ["password varchar(255) NOT NULL"],
            ["liczba int"],
            ["data DATE"],
        ]).execute();
    }

    // Create run down function
    function runDown() {
        Query().dropTable("character").execute();
    }
}
//Use run up
TestMigration().run();

//Use run down
TestMigration().down();
[Image: Quarchodr_sheqnnr.png]
Reply


Messages In This Thread
[Server] ORM - by Quarchodron - 01.07.2020, 12:36
RE: [Server] ORM - by Patrix - 01.07.2020, 13:49
RE: [Server] ORM - by Quarchodron - 01.07.2020, 14:11
RE: [Server] ORM - by Quarchodron - 08.07.2020, 09:19
RE: [Server] ORM - by Sative - 12.07.2020, 10:15

Possibly Related Threads…
Thread Author Replies Views Last Post
  [0.1.3] [server] ItemGroundSpawner HammelGammel 1 1,980 05.02.2020, 17:40
Last Post: demor140202
  [0.1.4.*] [client/server] Simple anty-cheat Profesores 8 4,941 20.03.2018, 18:16
Last Post: Patrix
  [0.1.3] [client/server] BotCreator HammelGammel 22 13,120 08.02.2018, 21:02
Last Post: HammelGammel
  [0.1.3] [client/server] Utility Scripts HammelGammel 1 2,783 27.01.2018, 13:03
Last Post: HammelGammel
  [G2O v.0.1.2][Server-Side] NPC Manager Quarchodron 16 9,047 21.01.2018, 18:59
Last Post: Quarchodron

Forum Jump:


Users browsing this thread: 1 Guest(s)