bogdanpolak / dataset-generator Goto Github PK
View Code? Open in Web Editor NEWDataSet Generator - generate code constructing fake memory dataset
License: MIT License
DataSet Generator - generate code constructing fake memory dataset
License: MIT License
Add option:
type
TAppendMode = (amMultilineAppends, amSinglelineAppends);
TDSGenerator = class (TComponent)
property AppendMode: TAppendMode ... ;
In the first mode component is generating same code as before, but in new mode (amSinglelineAppends
) it should generate single AppendRecord
method for the whole data row:
with ds do
begin
AppendRecord ([ 1, ''Ala ma kota'', EncodeDate(2019,9,16), 1.2, 1200]);
AppendRecord ([2, ''Ala ma kota'', Null, 950]);
Post;
end;
Method: TDSGenerator.GenerateAppendsBlock
is not persisting original dataset position (current row / record).
Add method generating:
GenerateAndSaveToStream (ds, stream)
GenerateAndSaveToFile (ds, fileName)
Update main README file and samples:
GenerateAsString
GenerateAsArray
GenerateAndSaveToStream / GenerateAndSaveToFile
GenerateAndSaveToClipboard
IdentationText
GenerateCode
AppendMode
GenerateDataSet
TDSGenerator
Update project sample
not delivered in current version (1.2) where it was requested
Remove with
sections:
ds.Append;
ds.FieldByName(''id'').Value := 1;
ds.FieldByName(''text1'').Value := ''Alice has a cat';
ds.Post;
ds.Append;
ds.FieldByName(''id'').Value := 2;
ds.FieldByName(''text1'').Value := ''Cat has a'';
ds.Post;
GenerateAndSaveToFile
is generating invalid file: unit name is default uSampleDataSet and file name is provided though parameter doesn't changes unit name
Method GenerateAndSaveToFile
call:
TDSGenerator.GenerateAndSaveToFile(aDataSet,
'FakeDataSet.Historical.pas');
generates:
unit uSampleDataSet;
but expected is:
unit FakeDataSet.Historical;
Add new option:
TGenerateDataSetType = (genClientDS, genFDMemTable);
...
GenerateDataSet: TGenerateDataSetType;
Replace TMemo with Scorecards Tiles
Related to #39
generators
=> sample
generators/Dataset2Code.dproj
=> sample/DemoGenerateDataSet.dproj
tests/DUnitxDatasetToCode.dproj
=> tests/TestDSGenerator.dproj
Should be:
with ds do
begin
Append;
FieldByName('ISBN').Value := '978-0321127426';
FieldByName('Title').Value := 'Patterns of Enterprise Application Architecture';
Post;
end;
with ds do
begin
Append;
FieldByName('ISBN').Value := '978-1849689121';
FieldByName('Title').Value :=
'Applied Architecture Patterns on the Microsoft Platform (Second Edit'+
'ion)';
Post;
end;
Now is:
with ds do
begin
Append;
FieldByName('ISBN').Value := '978-0321127426';
FieldByName('Title').Value := 'Patterns of Enterprise Application Architecture';
Post;
Append;
FieldByName('ISBN').Value := '978-1849689121';
FieldByName('Title').Value :=
'Applied Architecture Patterns on the Microsoft Platform (Second Edit'+
'ion)';
Post;
end;
Improve divide long string litterals (76+ chars):
Should:
FieldByName('Description').Value :=
'Covers Dependency Injection, you''ll learn about Constructor Injection' +
', Property Injection, and Method Injection and about the right and' +
' wrong way to use it';
Now:
FieldByName('Description').Value :=
'Covers Dependency Injection, you''ll learn about Constructor Injection, Pro' +
'perty Injection, and Method Injection and about the right andwrong way to u' +
'se it';
Can't generate mock data in TFDMemTable for TBCDField.
FieldDefs.Add('Price', ftBCD, 2);
(two size parameters)Investigate:
TGeneratorOptions = record
IndentationText: String;
DataSetType: TDataSetType;
AppendMode: TAppendMode;
MaxRows: Integer;
end;
and overloaded methods:
GenerateAsString(ds: TDataSet; const options: TGeneratorOptions): string;
GenerateAsArray(ds: TDataSet; const options: TGeneratorOptions): TArray<String>;
GenerateAndSaveToStream(ds: TDataSet; aStream: TStream; const options: TGeneratorOptions);
GenerateAndSaveToFile(ds: TDataSet; const aFileName: string; const options: TGeneratorOptions);
GenerateAndSaveClipboard(ds: TDataSet; const options: TGeneratorOptions);
Generate TBlobFields encoded as Base64
Add new property:
GenerateBlobFields: boolean
- default: `False'
Related to:
bogdanpolak/class-helpers#40
https://github.com/bogdanpolak/class-helpers/blob/master/src/Helper.TBytes.pas
TBytesHelper.GenerateBase64Code()
TBytesHelper.InitialiseFromBase64String()
Checkout: Frame.ByteAndStreamHelpers.pas
:
https://github.com/bogdanpolak/class-helpers/blob/master/examples/01-playground/Frame.ByteAndStreamHelpers.pas
unit {UnitName};
default: fUnitName = uSampleDataSet
2) factory method interface declaration:
function GivienDataSet (aOwner: TComponent): TDataSet;
function GivienDataSet (aOwner: TComponent): TDataSet;
begin
Remove protected methods from TDSGenerator
(exposed for unit tests) and delete class TDSGeneratorUnderTest
Refine the possibility of decomposition this item into several smaller Stories
Property should be used for each indentation. Requires #10.
Warning! Could require big refactoring in test code (templates with indentation: use right arrow char (→ ◇ ↩ ↦ ▷)
function CreateDataSet (AOwner: TComponent): Data.DB.TDataSet;
var
ds: TFDMemTable;
begin
ds := TFDMemTable.Create(AOwner);
with ds do
begin
FieldDefs.Add('id', ftInteger);
FieldDefs.Add('text1', ftWideString, 30);
FieldDefs.Add('date1', ftDate);
FieldDefs.Add('float1', ftFloat);
FieldDefs.Add('currency1', ftCurrency);
CreateDataSet;
AppendRecord([1, 'Ala ma kota', EncodeDate(2019, 09, 16), 1.2, 1200]);
AppendRecord([2, 'Ala ma kota', System.Variants.Null, Null, 950]);
end;
ds.First;
Result := ds;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Generator: TGenerateDataSetCode;
begin
Generator := TGenerateDataSetCode.Create(Self);
Generator.DataSet := CreateDataSet(Generator);
GenerateDataSetCode.Execute;
Memo1.Lines := GenerateDataSetCode.Code;
Generator.Free;
end;
Memo1 content
ds := TFDMemTable.Create(AOwner);
with ds do
begin
FieldDefs.Add(''id'', ftInteger);
FieldDefs.Add(''text1'', ftWideString, 30);
FieldDefs.Add(''date1'', ftDate);
FieldDefs.Add(''float1'', ftFloat);
FieldDefs.Add(''currency1'', ftCurrency);
CreateDataSet;
end;
with ds do
begin
Append;
FieldByName(''id'').Value := 1;
FieldByName(''text1'').Value := ''Ala ma kota'';
FieldByName(''date1'').Value := EncodeDate(2019,9,16);
FieldByName(''float1'').Value := 1.2;
FieldByName(''currency1'').Value := 1200;
Post;
end;
with ds do
begin
Append;
FieldByName(''id'').Value := 2;
FieldByName(''text1'').Value := ''Ala ma kota'';
FieldByName(''currency1'').Value := 950;
Post;
end;
Add properties to component TGenerateDataSetCode
Footer
as aboveBuild new sample project with TOrdersView
:
function TOrdersView.SelectMonth;
var
aDate: TDateTime;
begin
aDate := fMonthSelector.Execute;
aDataSet := fDataSetFactory.ConstructSelectDataset(
SQL_SELECT_CustomerOrders_FromOneMonth,
[YearOf(aDate), MonthOf(aDate)] );
SetMasterDataset(aDataSet);
end;
And test ImpactSales with Fake dataset:
procedure TestOrdersView.Setup;
begin
fOwner := TComponent.Create;
fOrderModelMock := TMock<IOrdersModel>.Create;
fOrdersView := TOrdersView.Create(fOrderModelMock);
// ...
end;
procedure TestOrdersView.Test_CalculateCurrentImpact;
var
aFakeOrdersDataSet: TDataSet;
actualImpact: Extended;
begin
aFakeOrdersDataSet := CreateDataSet(fOwner);
fOrdersView.SetMasterDataset(aFakeOrdersDataSet);
actualImpact := fOrdersView.GetCurrentImpact;
Assert.AreEqual(0.054, actualImpact, 0.0000001);
end;
Remove protected methods from TDSGenerator
(exposed for unit tests) and delete class TDSGeneratorUnderTest
Refine the possibility of decomposition this item into several smaller Stories
TAppendMode = (amMultilineAppend, amSinglelineAppend, amAppendRows);
amAppendRows mode:
ds.AppendRows([
[1, 'Team integration', EncodeDate(2019, 09, 16), 1.2, 1200],
[2, 'Progress retrospective', Null, Null, 950]
]);
convert double apostrophes ''
into single '
in sample code used in main README.md
Implement:
Related to: #39
aGenerator := TDSGenerator.Create(fOwner);
aGenerator.DataSet := fdqOrdesInYear;
aGenerator.Filter := Format(
'ShipVia = %d and EmployeeID = %d and OrderDate >= %d and OrderDate < %d',
[1, 8, Round(EncodeDate(1998,01,01)), Round(EncodeDate(1998,01,31)+1)]);
aGenerator.Execute;
Option
type
TGeneratorMode = genAll (default), genStructure, genAppend);
TDSGenerator = class(TComponent)
// ...
property GeneratorMode: TGeneratorMode ...;
One Code property
Change:
// property CodeWithStructure: TStrings read FCodeWithStructue;
// property CodeWithAppendData: TStrings read FCodeWithAppendData;
property Code: TStrings read FCode
has influence on methods:
GenerateAsString
GenerateAsArray
Update items:
with
] ds.First;
{$ENDREGION}
11.2
{* ------------------------------------------------------------------------
* ♥
* ♥ DataSet to Delphi Code (create TFDMemTable with the data)
* ♥
* Component: TDSGenerator
* Project: https://github.com/bogdanpolak/datasetToDelphiCode
* ------------------------------------------------------------------------ }
Removed version-bumper
sources from this project. Left here only bumper configuration with README and link for the sources
Current sources are in https://github.com/bogdanpolak/version-bumper
version-bumper.md
:
## Tool: Version Bumper - console application
repo: https://github.com/bogdanpolak/version-bumper
In working directory of project in Windows machine there are some uncommitted changes
Change property Code: TStrings read FCode;
into:
property CodeWithStructure: TStrings read FCode;
property CodeWithAppendData: TStrings read FCode;
CodeWithStructure
ds := TFDMemTable.Create(AOwner);
with ds do
begin
FieldDefs.Add(''id'', ftInteger);
FieldDefs.Add(''text1'', ftWideString, 30);
FieldDefs.Add(''date1'', ftDate);
FieldDefs.Add(''float1'', ftFloat);
FieldDefs.Add(''currency1'', ftCurrency);
CreateDataSet;
end;
CodeWithAppendData
:with ds do
begin
Append;
FieldByName(''id'').Value := 1;
FieldByName(''text1'').Value := ''Ala ma kota'';
FieldByName(''date1'').Value := EncodeDate(2019,9,16);
FieldByName(''float1'').Value := 1.2;
FieldByName(''currency1'').Value := 1200;
Post;
Append;
FieldByName(''id'').Value := 2;
FieldByName(''text1'').Value := ''Ala ma kota'';
FieldByName(''currency1'').Value := 950;
Post;
end;
GenerateAndSaveToClipboard (ds)
class function TDSGenerator.
GenerateAsArray(ds: TDataSet): TStringDynArray;
type
TFormMaim = class(TForm)
public const
Version = '1.4';
Divide long string litterals into chunks, each 76 characters lenght. Algotrhim shuld divide whole worlds (line lenght less or equal to 76 chars).
Should be:
FieldByName('Description').Value :=
'Covers Dependency Injection, you''ll learn about Constructor Injection' +
', Property Injection, and Method Injection and about the right and' +
' wrong way to use it';
Refactor code in src
folder info one unit to allow easy copy to other Delphi projects
actual:
TGeneratorMode = (genAll, genStructure, genAppend, genUnit, genFunction);
expected:
TGeneratorMode= (genStructure, genAppend, genFunction, genUnit);
Default mode = genFunction
Code Generator TGenerateDataSetCode
should have property IndentationText: string
Add property IndentationText
Given developer willing to set up indentation text for each line of the generated code
When ...
And ..
Then ...
Add signature and register component version in this.
Discussion: Please suggest signature templete (how to automaticly verify version?). Maybe version can be write down in component const
section?
Warning: [dcc32 Warning] Comp.Generator.DataSetCode.pas(71): W1009 Redeclaration of 'UnitName' hides a member in the base class
in:
type
TDSGenerator = class(TComponent)
...
property UnitName: string read fUnitName write fUnitName;
end;
Rename fUnitName
-> fNameOfUnit
Serach for UnitName in tests and samples (warning code can be compiled even with partial rename)
Create new option MaxInserts
:
MaxInserts
= 0 (generate all rows)MaxInserts
= n (generate n rows)Stary:
with ds do
begin
Append;
...
end;
Nowy:
{$REGION 'Append data to MemTable'}
with ds do
begin
Append;
...
end;
{$ENDREGION}
Test.Common.TTestGenerate
ds := GivenSampleDataSet (aOwner)
fOwner: TComponent
to manage dataset memoryAdd code
function Create_ABC_DataSet: TDataSet;
var
ds: TFDMemTable;
begin
ds := TFDMemTable.Create(Self);
// Old code
ds.First;
Result := ds;
end;
Update function Gen_UnitHeader
according to Proxy generator changes:
function TDataProxyGenerator.Gen_UnitHeader: string;
begin
Result :=
{} 'unit Proxy.' + fObjectName + ';'+ sLineBreak +
{} sLineBreak;
end;
Refactor option TGeneratorMode
to:
TGeneratorMode = (genStructure, genAppend, genFunction, genUnit);
with default value = genFunction
UPDATE DOC
Generator.DataSetType:= dstClientDataSet;
actualCode := Generator.GenFunction;
actualCode is not compiling (TClientDataSet
can't be assigned to TFDMemTable
):function CreateDataSet (aOwner: TComponent): TDataSet;
var
ds: TFDMemTable;
begin
ds := TClientDataSet.Create(AOwner);
TDSGenerator.GenFunction
not to use Execute (string lists)Generated long string literals can have variable length: default = 76 chars
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.