Skip to content

Commit 32c0b35

Browse files
v0.7.4
1 parent 60ef10a commit 32c0b35

5 files changed

Lines changed: 83 additions & 61 deletions

File tree

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 NodeJS](https://img.shields.io/badge/Arnelify%20ORM%20for%20NodeJS-0.7.3-yellow) ![C++](https://img.shields.io/badge/C++-2b-red) ![G++](https://img.shields.io/badge/G++-14.2.0-blue) ![NodeJS](https://img.shields.io/badge/NodeJS-22.13.1-green) ![Bun](https://img.shields.io/badge/Bun-1.2.0-green)
3+
![Arnelify ORM for NodeJS](https://img.shields.io/badge/Arnelify%20ORM%20for%20NodeJS-0.7.4-yellow) ![C++](https://img.shields.io/badge/C++-2b-red) ![G++](https://img.shields.io/badge/G++-14.2.0-blue) ![NodeJS](https://img.shields.io/badge/NodeJS-22.13.1-green) ![Bun](https://img.shields.io/badge/Bun-1.2.0-green)
44

55
## 🚀 About
66
**Arnelify® ORM for NodeJS** - is a minimalistic NodeJS (Bun) Addon which is an ORM written in C and C++.
@@ -53,7 +53,7 @@ This software is licensed under the <a href="https://github.com/arnelify/arnelif
5353
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.
5454

5555
## ⭐ Release Notes
56-
Version 0.7.3 - NodeJS (Bun) Addon
56+
Version 0.7.4 - NodeJS (Bun) Addon
5757

5858
We are excited to introduce the Arnelify ORM for NodeJS (Bun) addon! Please note that this version is raw and still in active development.
5959

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "arnelify-orm",
3-
"version": "0.7.3",
3+
"version": "0.7.4",
44
"description": "Minimalistic NodeJS (Bun) addon which is an ORM written in C and C++.",
55
"keywords": [
66
"arnelify",

src/mysql/query/index.ts

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,28 @@ class MySQLQuery {
8686
return false;
8787
}
8888

89+
/**
90+
* Has Group Condition
91+
* @returns
92+
*/
93+
#hasGroupCondition() {
94+
return this.#query.endsWith(")");
95+
}
96+
97+
/**
98+
* Has Condition
99+
* @returns
100+
*/
101+
#hasCondition() {
102+
const tokens: string[] = this.#query.split(' ');
103+
if (tokens.length < 3) return false;
104+
105+
const op: string = tokens[tokens.length - 2];
106+
const rhs: string = tokens[tokens.length - 1];
107+
if (rhs === 'IS NULL') return true;
108+
return this.#isOperator(op);
109+
}
110+
89111
/**
90112
* Alter Table
91113
* @param {string} tableName
@@ -317,8 +339,7 @@ class MySQLQuery {
317339

318340
if (typeof arg1 === 'function') {
319341
if (this.#hasHaving) {
320-
const hasCondition: boolean = this.#query.endsWith(')');
321-
if (hasCondition) this.#query += ' AND ';
342+
if (this.#hasGroupCondition()) this.#query += ' AND ';
322343
} else {
323344
this.#query += ' HAVING ';
324345
this.#hasHaving = true;
@@ -331,8 +352,7 @@ class MySQLQuery {
331352
}
332353

333354
if (this.#hasHaving) {
334-
const hasCondition: boolean = this.#query.endsWith('?');
335-
if (hasCondition) this.#query += ' AND ';
355+
if (this.#hasCondition()) this.#query += ' AND ';
336356
} else {
337357
this.#query += ' HAVING ';
338358
this.#hasHaving = true;
@@ -468,8 +488,7 @@ class MySQLQuery {
468488
arg3: null | number | string = null): MySQLQuery {
469489
if (typeof arg1 === 'function') {
470490
if (this.#hasOn) {
471-
const hasCondition: boolean = this.#query.endsWith(')');
472-
if (hasCondition) this.#query += ' AND ';
491+
if (this.#hasGroupCondition()) this.#query += ' AND ';
473492
} else {
474493
this.#query += ' ON ';
475494
this.#hasOn = true;
@@ -482,8 +501,7 @@ class MySQLQuery {
482501
}
483502

484503
if (this.#hasOn) {
485-
const hasCondition: boolean = this.#query.endsWith('?');
486-
if (hasCondition) this.#query += ' AND ';
504+
if (this.#hasCondition()) this.#query += ' AND ';
487505
} else {
488506
this.#query += ' ON ';
489507
this.#hasOn = true;
@@ -524,8 +542,7 @@ class MySQLQuery {
524542
arg3: null | number | string = null): MySQLQuery {
525543
if (typeof arg1 === 'function') {
526544
if (this.#hasHaving) {
527-
const hasCondition: boolean = this.#query.endsWith(')');
528-
if (hasCondition) this.#query += ' OR ';
545+
if (this.#hasGroupCondition()) this.#query += ' OR ';
529546
} else {
530547
this.#query += ' HAVING ';
531548
this.#hasHaving = true;
@@ -538,8 +555,7 @@ class MySQLQuery {
538555
}
539556

540557
if (this.#hasHaving) {
541-
const hasCondition: boolean = this.#query.endsWith('?');
542-
if (hasCondition) this.#query += ' OR ';
558+
if (this.#hasCondition()) this.#query += ' OR ';
543559
} else {
544560
this.#query += ' HAVING ';
545561
this.#hasHaving = true;
@@ -561,8 +577,7 @@ class MySQLQuery {
561577
arg3: null | number | string = null): MySQLQuery {
562578
if (typeof arg1 === 'function') {
563579
if (this.#hasOn) {
564-
const hasCondition: boolean = this.#query.endsWith(')');
565-
if (hasCondition) this.#query += ' OR ';
580+
if (this.#hasGroupCondition()) this.#query += ' OR ';
566581
} else {
567582
this.#query += ' ON ';
568583
this.#hasOn = true;
@@ -575,8 +590,7 @@ class MySQLQuery {
575590
}
576591

577592
if (this.#hasOn) {
578-
const hasCondition: boolean = this.#query.endsWith('?');
579-
if (hasCondition) this.#query += ' OR ';
593+
if (this.#hasCondition()) this.#query += ' OR ';
580594
} else {
581595
this.#query += ' ON ';
582596
this.#hasOn = true;
@@ -598,8 +612,7 @@ class MySQLQuery {
598612
arg3: null | number | string = null): MySQLQuery {
599613
if (typeof arg1 === 'function') {
600614
if (this.#hasWhere) {
601-
const hasCondition: boolean = this.#query.endsWith(')');
602-
if (hasCondition) this.#query += ' OR ';
615+
if (this.#hasGroupCondition()) this.#query += ' OR ';
603616
} else {
604617
this.#query += ' WHERE ';
605618
this.#hasWhere = true;
@@ -612,9 +625,7 @@ class MySQLQuery {
612625
}
613626

614627
if (this.#hasWhere) {
615-
const hasCondition: boolean = this.#query.endsWith('?')
616-
|| this.#query.endsWith('IS NULL');
617-
if (hasCondition) this.#query += ' OR ';
628+
if (this.#hasCondition()) this.#query += ' OR ';
618629
} else {
619630
this.#query += ' WHERE ';
620631
this.#hasWhere = true;
@@ -749,8 +760,7 @@ class MySQLQuery {
749760
arg3: null | number | string = null): MySQLQuery {
750761
if (typeof arg1 === 'function') {
751762
if (this.#hasWhere) {
752-
const hasCondition: boolean = this.#query.endsWith(')');
753-
if (hasCondition) this.#query += ' AND ';
763+
if (this.#hasGroupCondition()) this.#query += ' AND ';
754764
} else {
755765
this.#query += ' WHERE ';
756766
this.#hasWhere = true;
@@ -763,9 +773,7 @@ class MySQLQuery {
763773
}
764774

765775
if (this.#hasWhere) {
766-
const hasCondition: boolean = this.#query.endsWith('?')
767-
|| this.#query.endsWith('IS NULL');
768-
if (hasCondition) this.#query += ' AND ';
776+
if (this.#hasCondition()) this.#query += ' AND ';
769777
} else {
770778
this.#query += ' WHERE ';
771779
this.#hasWhere = true;

src/src/mysql/query/index.h

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class MySQLQuery {
5858
const std::variant<std::nullptr_t, int, double, std::string>& arg3) {
5959
if (this->isOperator(arg2)) {
6060
const std::string operator_ = std::get<std::string>(arg2);
61+
6162
if (std::holds_alternative<std::nullptr_t>(arg3)) {
6263
this->query += column + " IS NULL";
6364
return;
@@ -84,6 +85,7 @@ class MySQLQuery {
8485
}
8586

8687
this->query += column + " " + operator_ + " " + value;
88+
return;
8789
}
8890

8991
const std::string value = std::get<std::string>(arg3);
@@ -94,6 +96,7 @@ class MySQLQuery {
9496
}
9597

9698
this->query += column + " " + operator_ + " " + value;
99+
return;
97100
}
98101

99102
if (std::holds_alternative<std::nullptr_t>(arg2)) {
@@ -110,6 +113,7 @@ class MySQLQuery {
110113
}
111114

112115
this->query += column + " = " + value;
116+
return;
113117
}
114118

115119
if (std::holds_alternative<double>(arg2)) {
@@ -121,17 +125,40 @@ class MySQLQuery {
121125
}
122126

123127
this->query += column + " = " + value;
128+
return;
124129
}
125130

126131
const std::string value = std::get<std::string>(arg2);
127132
if (bind) {
128133
this->query += column + " = ?";
129134
this->bindings.emplace_back(value);
135+
return;
130136
}
131137

132138
this->query += column + " = " + value;
133139
}
134140

141+
const bool hasGroupCondition() {
142+
return this->query.ends_with(")");
143+
}
144+
145+
const bool hasCondition() {
146+
std::vector<std::string> tokens;
147+
std::istringstream stream(this->query);
148+
std::string token;
149+
while (stream >> token) {
150+
tokens.push_back(token);
151+
}
152+
153+
if (tokens.size() < 3) return false;
154+
155+
const std::string& lhs = tokens[tokens.size() - 3];
156+
const std::string& op = tokens[tokens.size() - 2];
157+
const std::string& rhs = tokens[tokens.size() - 1];
158+
159+
return isOperator(op);
160+
}
161+
135162
public:
136163
MySQLQuery() : hasHaving(false), hasOn(false), hasWhere(false) {}
137164

@@ -343,8 +370,7 @@ class MySQLQuery {
343370

344371
MySQLQuery* having(const std::function<void(MySQLQuery*)>& condition) {
345372
if (this->hasHaving) {
346-
const bool hasCondition = this->query.ends_with(")");
347-
if (hasCondition) this->query += " AND ";
373+
if (this->hasGroupCondition()) this->query += " AND ";
348374
} else {
349375
this->query += " HAVING ";
350376
this->hasHaving = true;
@@ -362,8 +388,7 @@ class MySQLQuery {
362388
const std::variant<std::nullptr_t, int, double, std::string>& arg3 =
363389
nullptr) {
364390
if (this->hasHaving) {
365-
const bool hasCondition = this->query.ends_with("?");
366-
if (hasCondition) this->query += " AND ";
391+
if (this->hasCondition()) this->query += " AND ";
367392
} else {
368393
this->query += " HAVING ";
369394
this->hasHaving = true;
@@ -470,8 +495,7 @@ class MySQLQuery {
470495

471496
MySQLQuery* on(const std::function<void(MySQLQuery*)>& condition) {
472497
if (this->hasOn) {
473-
const bool hasCondition = this->query.ends_with(")");
474-
if (hasCondition) this->query += " AND ";
498+
if (this->hasGroupCondition()) this->query += " AND ";
475499
} else {
476500
this->query += " ON ";
477501
this->hasOn = true;
@@ -489,8 +513,7 @@ class MySQLQuery {
489513
const std::variant<std::nullptr_t, int, double, std::string>& arg3 =
490514
nullptr) {
491515
if (this->hasOn) {
492-
const bool hasCondition = this->query.ends_with("?");
493-
if (hasCondition) this->query += " AND ";
516+
if (this->hasCondition()) this->query += " AND ";
494517
} else {
495518
this->query += " ON ";
496519
this->hasOn = true;
@@ -513,8 +536,7 @@ class MySQLQuery {
513536

514537
MySQLQuery* orHaving(const std::function<void(MySQLQuery*)>& condition) {
515538
if (this->hasHaving) {
516-
const bool hasCondition = this->query.ends_with(")");
517-
if (hasCondition) this->query += " OR ";
539+
if (this->hasGroupCondition()) this->query += " OR ";
518540
} else {
519541
this->query += " HAVING ";
520542
this->hasHaving = true;
@@ -532,8 +554,7 @@ class MySQLQuery {
532554
const std::variant<std::nullptr_t, int, double, std::string>& arg3 =
533555
nullptr) {
534556
if (this->hasHaving) {
535-
const bool hasCondition = this->query.ends_with("?");
536-
if (hasCondition) this->query += " OR ";
557+
if (this->hasCondition()) this->query += " OR ";
537558
} else {
538559
this->query += " HAVING ";
539560
this->hasHaving = true;
@@ -545,8 +566,7 @@ class MySQLQuery {
545566

546567
MySQLQuery* orOn(const std::function<void(MySQLQuery*)>& condition) {
547568
if (this->hasOn) {
548-
const bool hasCondition = this->query.ends_with(")");
549-
if (hasCondition) this->query += " OR ";
569+
if (this->hasGroupCondition()) this->query += " OR ";
550570
} else {
551571
this->query += " ON ";
552572
this->hasOn = true;
@@ -564,8 +584,7 @@ class MySQLQuery {
564584
const std::variant<std::nullptr_t, int, double, std::string>& arg3 =
565585
nullptr) {
566586
if (this->hasOn) {
567-
const bool hasCondition = this->query.ends_with("?");
568-
if (hasCondition) this->query += " OR ";
587+
if (this->hasCondition()) this->query += " OR ";
569588
} else {
570589
this->query += " ON ";
571590
this->hasOn = true;
@@ -577,8 +596,7 @@ class MySQLQuery {
577596

578597
MySQLQuery* orWhere(const std::function<void(MySQLQuery*)>& condition) {
579598
if (this->hasWhere) {
580-
const bool hasCondition = this->query.ends_with(")");
581-
if (hasCondition) this->query += " OR ";
599+
if (this->hasGroupCondition()) this->query += " OR ";
582600
} else {
583601
this->query += " WHERE ";
584602
this->hasWhere = true;
@@ -596,9 +614,7 @@ class MySQLQuery {
596614
const std::variant<std::nullptr_t, int, double, std::string>& arg3 =
597615
nullptr) {
598616
if (this->hasWhere) {
599-
const bool hasCondition =
600-
this->query.ends_with("?") || this->query.ends_with("IS NULL");
601-
if (hasCondition) this->query += " OR ";
617+
if (this->hasCondition()) this->query += " OR ";
602618
} else {
603619
this->query += " WHERE ";
604620
this->hasWhere = true;
@@ -704,8 +720,7 @@ class MySQLQuery {
704720

705721
MySQLQuery* where(const std::function<void(MySQLQuery*)>& condition) {
706722
if (this->hasWhere) {
707-
const bool hasCondition = this->query.ends_with(")");
708-
if (hasCondition) this->query += " AND ";
723+
if (this->hasGroupCondition()) this->query += " AND ";
709724
} else {
710725
this->query += " WHERE ";
711726
this->hasWhere = true;
@@ -723,9 +738,7 @@ class MySQLQuery {
723738
const std::variant<std::nullptr_t, int, double, std::string>& arg3 =
724739
nullptr) {
725740
if (this->hasWhere) {
726-
const bool hasCondition =
727-
this->query.ends_with("?") || this->query.ends_with("IS NULL");
728-
if (hasCondition) this->query += " AND ";
741+
if (this->hasCondition()) this->query += " AND ";
729742
} else {
730743
this->query += " WHERE ";
731744
this->hasWhere = true;

0 commit comments

Comments
 (0)