Skip to content

Commit 015ffc0

Browse files
v0.7.1
1 parent 6618768 commit 015ffc0

12 files changed

Lines changed: 59 additions & 22 deletions

File tree

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ENGINE = g++
66
ENGINE_FLAGS = -std=c++2b
77

88
# PATH
9-
PATH_BIN = $(CURDIR)/tests/bin/index
9+
PATH_BIN = $(CURDIR)/tests/build/index.bin
1010
PATH_SRC = $(CURDIR)/tests/index.py
1111

1212
# INC
@@ -42,12 +42,12 @@ build:
4242
${PYTHON} ${PYTHON_FLAGS} index
4343

4444
test:
45-
clear && mkdir -p tests/bin && rm -rf tests/bin/*
45+
clear && mkdir -p tests/build && rm -rf tests/build/*
4646
${PYTHON} ${PYTHON_FLAGS} tests.index
4747

4848
test_nuitka:
49-
clear && mkdir -p tests/bin && rm -rf tests/bin/*
50-
${NUITKA} ${NUITKA_FLAGS} --output-dir=tests/bin ${PATH_SRC} && clear
49+
clear && mkdir -p tests/build && rm -rf tests/build/*
50+
${NUITKA} ${NUITKA_FLAGS} --output-dir=tests/build ${PATH_SRC} && clear
5151
${PATH_BIN}
5252

5353
.PHONY: build test

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<img src="https://static.wikia.nocookie.net/arnelify/images/c/c8/Arnelify-logo-2024.png/revision/latest?cb=20240701012515" style="width:336px;" alt="Arnelify Logo" />
22

3-
![Arnelify ORM for Python](https://img.shields.io/badge/Arnelify%20ORM%20for%20Python-0.7.0-yellow) ![C++](https://img.shields.io/badge/C++-2b-red) ![G++](https://img.shields.io/badge/G++-14.2.0-blue) ![Python](https://img.shields.io/badge/Python-3.11.2-blue) ![Nuitka](https://img.shields.io/badge/Nuitka-2.6.4-blue)
3+
![Arnelify ORM for Python](https://img.shields.io/badge/Arnelify%20ORM%20for%20Python-0.7.1-yellow) ![C++](https://img.shields.io/badge/C++-2b-red) ![G++](https://img.shields.io/badge/G++-14.2.0-blue) ![Python](https://img.shields.io/badge/Python-3.11.2-blue) ![Nuitka](https://img.shields.io/badge/Nuitka-2.6.4-blue)
44

55
## 🚀 About
66
**Arnelify® ORM for Python** - is a minimalistic dynamic library which is an ORM written in C and C++.
@@ -55,7 +55,7 @@ This software is licensed under the <a href="https://github.com/arnelify/arnelif
5555
Join us to help improve this software, fix bugs or implement new functionality. Active participation will help keep the software up-to-date, reliable, and aligned with the needs of its users.
5656

5757
## ⭐ Release Notes
58-
Version 0.7.0 - Minimalistic dynamic library
58+
Version 0.7.1 - Minimalistic dynamic library
5959

6060
We are excited to introduce the Arnelify ORM dynamic library for Python! Please note that this version is raw and still in active development.
6161

arnelify_orm/mysql/index.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ def __init__(self, opts: dict):
4949
cOpts = self.ffi.new("char[]", self.opts.encode('utf-8'))
5050
self.lib.orm_mysql_create(cOpts)
5151

52+
def foreignKeyChecks(self, on: bool = True) -> None:
53+
builder: MySQLQuery = MySQLQuery()
54+
builder.setGetUuIdCallback(self.getUuId)
55+
56+
def onQuery(query, bindings):
57+
return self.exec(query, bindings)
58+
59+
builder.onQuery(onQuery)
60+
builder.foreignKeyChecks(on)
61+
5262
def alterTable(self, tableName: str, condition: callable) -> None:
5363
builder: MySQLQuery = MySQLQuery()
5464
builder.setGetUuIdCallback(self.getUuId)

arnelify_orm/mysql/query/index.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,11 @@ def dropIndex(self, name: str) -> None:
175175
self.query += f"DROP INDEX {name}"
176176

177177
def dropTable(self, tableName: str, args: list[str] = []) -> None:
178-
self.exec('SET foreign_key_checks = 0;')
179178
self.query = f"DROP TABLE IF EXISTS {tableName}"
180179
for arg in args:
181180
self.query += f" {arg}"
182181

183182
self.exec()
184-
self.exec('SET foreign_key_checks = 1;')
185183

186184
def exec(self, query: str | None = None, bindings: list[str] = []) -> list[dict]:
187185
res: list[dict] = []
@@ -203,6 +201,13 @@ def exec(self, query: str | None = None, bindings: list[str] = []) -> list[dict]
203201

204202
return res
205203

204+
def foreignKeyChecks(self, on: bool = True) -> None:
205+
if on:
206+
self.exec('SET foreign_key_checks = 1;')
207+
return
208+
209+
self.exec('SET foreign_key_checks = 0;')
210+
206211
def getUuId(self) -> str:
207212
return self.getUuIdCallback()
208213

arnelify_orm/src/mysql/index.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ class MySQL {
127127
return res;
128128
}
129129

130+
const void foreignKeyChecks(const bool& on = true) {
131+
MySQLQuery* builder = new MySQLQuery();
132+
builder->onQuery([this, builder](const std::string& query,
133+
const std::vector<std::string>& bindings) {
134+
this->trash.push_back(builder);
135+
return this->exec(query, bindings);
136+
});
137+
138+
builder->foreignKeyChecks(on);
139+
}
140+
130141
const std::string getUuId() {
131142
MySQLQuery builder;
132143
return builder.getUuId();

arnelify_orm/src/mysql/query/index.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,6 @@ class MySQLQuery {
135135
public:
136136
MySQLQuery() : hasHaving(false), hasOn(false), hasWhere(false) {}
137137

138-
void onQuery(std::function<MySQLRes(const std::string&,
139-
const std::vector<std::string>&)>
140-
callback) {
141-
this->callback = callback;
142-
}
143-
144138
void alterTable(
145139
const std::string& tableName,
146140
const std::function<void(MySQLQuery*)>& condition =
@@ -256,14 +250,12 @@ class MySQLQuery {
256250

257251
void dropTable(const std::string& tableName,
258252
const std::vector<std::string> args = {}) {
259-
this->exec("SET foreign_key_checks = 0;");
260253
this->query = "DROP TABLE IF EXISTS " + tableName;
261254
for (size_t i = 0; args.size() > i; i++) {
262255
this->query += " " + args[i];
263256
}
264257

265258
this->exec();
266-
this->exec("SET foreign_key_checks = 1;");
267259
}
268260

269261
MySQLRes exec() {
@@ -299,6 +291,15 @@ class MySQLQuery {
299291
return res;
300292
}
301293

294+
void foreignKeyChecks(const bool& on = true) {
295+
if (on) {
296+
this->exec("SET foreign_key_checks = 1;");
297+
return;
298+
}
299+
300+
this->exec("SET foreign_key_checks = 0;");
301+
}
302+
302303
const std::string getUuId() {
303304
std::random_device rd;
304305
std::mt19937 gen(rd());
@@ -460,6 +461,11 @@ class MySQLQuery {
460461
return this;
461462
}
462463

464+
MySQLQuery* offset(const int& offset) {
465+
this->query += " OFFSET " + std::to_string(offset);
466+
return this;
467+
}
468+
463469
MySQLQuery* on(const std::function<void(MySQLQuery*)>& condition) {
464470
if (this->hasOn) {
465471
const bool hasCondition = this->query.ends_with(")");
@@ -492,9 +498,10 @@ class MySQLQuery {
492498
return this;
493499
}
494500

495-
MySQLQuery* offset(const int& offset) {
496-
this->query += " OFFSET " + std::to_string(offset);
497-
return this;
501+
void onQuery(std::function<MySQLRes(const std::string&,
502+
const std::vector<std::string>&)>
503+
callback) {
504+
this->callback = callback;
498505
}
499506

500507
MySQLQuery* orderBy(const std::string& column, const std::string& arg2) {

arnelify_orm/src/tests/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
22

3-
bin/*
3+
build/*

arnelify_orm/src/tests/build/index

-554 KB
Binary file not shown.

arnelify_orm/src/tests/index.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ int main(int argc, char* argv[]) {
2020
db->connect();
2121
std::cout << "Connected." << std::endl;
2222

23+
db->foreignKeyChecks(false);
2324
db->dropTable("users");
2425
db->dropTable("posts");
26+
db->foreignKeyChecks(true);
2527

2628
db->createTable("users", [](MySQLQuery* query){
2729
query->column("id", "BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY");

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
setup(
1313
name="arnelify_orm",
14-
version="0.7.0",
14+
version="0.7.1",
1515
author="Arnelify",
1616
description="Minimalistic dynamic library which is an ORM written in C and C++.",
1717
url='https://github.com/arnelify/arnelify-orm-python',

0 commit comments

Comments
 (0)