01.07.2020, 13:36
(This post was last modified: 08.07.2020, 10:18 by Quarchodron.)
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.
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.
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.
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();