forked from HemulGM/SQLGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQLG.dpr
86 lines (75 loc) · 1.82 KB
/
SQLG.dpr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
program SQLG;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.TypInfo,
System.Rtti,
SQLG.Table in 'SQLG.Table.pas',
SQLG.Field in 'SQLG.Field.pas',
SQLG.Condition in 'SQLG.Condition.pas',
SQLG.Params in 'SQLG.Params.pas',
SQLG.Select in 'SQLG.Select.pas',
SQLG.CreateTable in 'SQLG.CreateTable.pas',
SQLG.Types in 'SQLG.Types.pas';
type
[TableName('user')]
TUser = class(TSQLTable)
[FieldName('id'),
UNIQUE,
PRIMARYKEY]
Id: TFGUID;
[FieldName('role_id')]
RoleId: TFGUID;
[FieldName('status')]
Status: TFInteger;
[FieldName('name')]
Name: TFString;
end;
[TableName('user_role')]
TUserRole = class(TSQLTable)
[FieldName('id')]
Id: TFGUID;
[FieldName('type')]
RoleType: TFInteger;
[FieldName('desc')]
Desc: TFString;
[FieldName('name'),
LENGTH(20)]
Name: TFVARCHAR;
end;
procedure Test;
begin
var User := TUser.Create;
var UserRole := TUserRole.Create;
var Params: TSQLParams;
var Sel :=
Select([User, UserRole.Desc.Table('ur').&As('description')]).
From(User).
LeftJoin(
Select('*').
From(UserRole).Where(UserRole.RoleType = 1), 'ur').
on(User.RoleId = UserRole.Id.Table('ur')).
Where(not (User.Id = TGUID.NewGuid) or (User.Status in [1, 2, 3])).
Where(User.Status and 1 = 0).
Where(User.Name = 'Dan').
Where(User.Status in
Select(User.Status).From(User).Where(User.RoleId in [TGUID.NewGuid, TGUID.NewGuid])).
OrderBy([User.Name, DESC(User.Status)]).
GroupBy([User.Id]);
writeln(Sel.Build(Params));
writeln;
for var Param in Params do
writeln(Param.Key, ': ', Param.Value.TypeInfo.Name, ' = ', Param.ToString);
User.Free;
UserRole.Free;
end;
begin
try
Test;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.