https://github.com/marcelolx/nowa
Simple query builder for Delphi, working with enumerators.
https://github.com/marcelolx/nowa
delphi pascal pascal-language query-builder
Last synced: about 2 months ago
JSON representation
Simple query builder for Delphi, working with enumerators.
- Host: GitHub
- URL: https://github.com/marcelolx/nowa
- Owner: marcelolx
- Created: 2018-07-31T05:58:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-29T00:59:06.000Z (almost 7 years ago)
- Last Synced: 2025-09-01T20:55:12.290Z (8 months ago)
- Topics: delphi, pascal, pascal-language, query-builder
- Language: Pascal
- Homepage:
- Size: 224 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Nowa
Simple SQL query builder for Delphi, working with enumerated types.
#### Info:
* In development.
# How to build queries
1. Do you need one enumerated type.
2. One class (that inherits ```TEnumAbstract``` and implements ```IEnum```) to map the database fields based on the enumerated type.
3. One model that inherits ```TModel``` and implements Set/GetValue functions declared on ```IModel``` that are virtual on base model.
4. Use classes of _NowaImpl.pas_ unit to build the queries.
An Simple select example:
```pascal
procedure NowaExample.TestExample;
var
oIPerson: IModel;
begin
oIPerson := TPerson.Create;
oIPerson.PrepareModel('', [tepSequential, tepName, tepEmail]);
TSQLSelect.Create.Ref
.Fields([oIPerson.Fields])
.From(oIPerson.Table)
.Build;
end;
```
Example select with InnerJoin:
```pascal
procedure NowaExample.TestExampleInnerJoin;
var
oIPerson: IPerson;
oIMatriculation: IModel;
SelectCommand: String;
begin
oIPerson := TPerson.Create;
oIMatriculation := TMatriculation.Create;
oIPerson.PrepareModel('', []);
oIMatriculation.PrepareModel('', []);
SelectCommand := TSQLSelect.Create.Ref
.Fields([oIPerson.Fields, oIMatriculation.Fields])
.From(oIPerson.Table)
.InnerJoin(
TSQLJoin.Create.Ref
.Table(oIMatriculation.Table)
.&On(
TSQLCondition.Create.Ref
.LeftTerm(oIMatriculation.Field(temPersonSequential))
.Op(opEqual)
.RightTerm(oIPerson.Field(tepSequential))
)
)
.Build;
end;
```
The output assigned to ```SelectCommand``` is:
```
SELECT PERSON.NR_SEQUENTIAL AS PERSON_SEQUENTIAL,
PERSON.FL_NAME AS PERSON_NAME,
PERSON.DT_BIRTHDATE AS PERSON_BIRTHDATE,
PERSON.TX_EMAIL AS PERSON_EMAIL,
PERSON.TX_PASSWORD AS PERSON_PASSWORD,
MATRICULATION.NR_SEQUENTIAL AS MATRICULATION_SEQUENTIAL,
MATRICULATION.NR_PERSONSEQUENTIAL AS MATRICULATION_PERSONSEQUENTIAL,
MATRICULATION.DT_DATE AS MATRICULATION_DATE,
MATRICULATION.CD_USER AS PERSON_USER
FROM TB_PERSON AS PERSON
INNER JOIN TB_MATRICULATION AS MATRICULATION ON (MATRICULATION.NR_PERSONSEQUENTIAL = PERSON.NR_SEQUENTIAL)
```
### _There is a lot to implement, but it is this idea that I want to follow._
# Getting Started
A. Create a unit named "Enumerator.Person".
B. Create an enumerated TEPerson, see:
```pascal
unit Enumerator.Person
interface
uses
Enumerator;
type
TEPerson = (tepSequential, tepName, tepBirthDate, tepEmail, tepPassword);
implementation
end.
```
C. Create a class who inherit TEnumAbstract and implements IEnum, see the class and function declarations:
```pascal
unit Enumerator.Person
interface
uses
Enumerator;
type
TEPerson = (tepSequential, tepName, tepBirthDate, tepEmail, tepPassword);
TEnumPessoa = class(TEnumAbstract, IEnum)
public
function Column(const AEnumeratedField: TEPerson): String; override;
function Table: String; override;
function TableAlias(const AAlias: String = ''): String; override;
function Sequence: String; override;
function AllColumns: TArray; override;
function Ref: IEnum; override;
end;
implementation
end.
```