Skip to content

Commit b5b0479

Browse files
committed
create the lazy elephant project and parse simple templates generating valid postgresql and c#
0 parents  commit b5b0479

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2114
-0
lines changed

Diff for: .gitignore

+245
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.userosscache
8+
*.sln.docstates
9+
10+
# User-specific files (MonoDevelop/Xamarin Studio)
11+
*.userprefs
12+
13+
# Build results
14+
[Dd]ebug/
15+
[Dd]ebugPublic/
16+
[Rr]elease/
17+
[Rr]eleases/
18+
x64/
19+
x86/
20+
build/
21+
bld/
22+
[Bb]in/
23+
[Oo]bj/
24+
25+
# Visual Studio 2015 cache/options directory
26+
.vs/
27+
# Uncomment if you have tasks that create the project's static files in wwwroot
28+
#wwwroot/
29+
30+
# MSTest test Results
31+
[Tt]est[Rr]esult*/
32+
[Bb]uild[Ll]og.*
33+
34+
# NUNIT
35+
*.VisualState.xml
36+
TestResult.xml
37+
38+
# Build Results of an ATL Project
39+
[Dd]ebugPS/
40+
[Rr]eleasePS/
41+
dlldata.c
42+
43+
# DNX
44+
project.lock.json
45+
artifacts/
46+
47+
wwwroot/css/*.min.css
48+
wwwroot/js/*.min.js
49+
wwwroot/lib/*
50+
wwwroot/posts
51+
52+
Posts/*
53+
verify.txt
54+
55+
*_i.c
56+
*_p.c
57+
*_i.h
58+
*.ilk
59+
*.meta
60+
*.obj
61+
*.pch
62+
*.pdb
63+
*.pgc
64+
*.pgd
65+
*.rsp
66+
*.sbr
67+
*.tlb
68+
*.tli
69+
*.tlh
70+
*.tmp
71+
*.tmp_proj
72+
*.log
73+
*.vspscc
74+
*.vssscc
75+
.builds
76+
*.pidb
77+
*.svclog
78+
*.scc
79+
80+
# Chutzpah Test files
81+
_Chutzpah*
82+
83+
# Visual C++ cache files
84+
ipch/
85+
*.aps
86+
*.ncb
87+
*.opendb
88+
*.opensdf
89+
*.sdf
90+
*.cachefile
91+
92+
# Visual Studio profiler
93+
*.psess
94+
*.vsp
95+
*.vspx
96+
*.sap
97+
98+
# TFS 2012 Local Workspace
99+
$tf/
100+
101+
# Guidance Automation Toolkit
102+
*.gpState
103+
104+
# ReSharper is a .NET coding add-in
105+
_ReSharper*/
106+
*.[Rr]e[Ss]harper
107+
*.DotSettings.user
108+
109+
# JustCode is a .NET coding add-in
110+
.JustCode
111+
112+
# TeamCity is a build add-in
113+
_TeamCity*
114+
115+
# DotCover is a Code Coverage Tool
116+
*.dotCover
117+
118+
# NCrunch
119+
_NCrunch_*
120+
.*crunch*.local.xml
121+
nCrunchTemp_*
122+
123+
# MightyMoose
124+
*.mm.*
125+
AutoTest.Net/
126+
127+
# Web workbench (sass)
128+
.sass-cache/
129+
130+
# Installshield output folder
131+
[Ee]xpress/
132+
133+
# DocProject is a documentation generator add-in
134+
DocProject/buildhelp/
135+
DocProject/Help/*.HxT
136+
DocProject/Help/*.HxC
137+
DocProject/Help/*.hhc
138+
DocProject/Help/*.hhk
139+
DocProject/Help/*.hhp
140+
DocProject/Help/Html2
141+
DocProject/Help/html
142+
143+
# Click-Once directory
144+
publish/
145+
146+
# Publish Web Output
147+
*.[Pp]ublish.xml
148+
*.azurePubxml
149+
# TODO: Comment the next line if you want to checkin your web deploy settings
150+
# but database connection strings (with potential passwords) will be unencrypted
151+
*.pubxml
152+
*.publishproj
153+
154+
# NuGet Packages
155+
*.nupkg
156+
# The packages folder can be ignored because of Package Restore
157+
**/packages/*
158+
# except build/, which is used as an MSBuild target.
159+
!**/packages/build/
160+
# Uncomment if necessary however generally it will be regenerated when needed
161+
#!**/packages/repositories.config
162+
163+
# Microsoft Azure Build Output
164+
csx/
165+
*.build.csdef
166+
167+
# Microsoft Azure Emulator
168+
ecf/
169+
rcf/
170+
171+
# Microsoft Azure ApplicationInsights config file
172+
ApplicationInsights.config
173+
174+
# Windows Store app package directory
175+
AppPackages/
176+
BundleArtifacts/
177+
178+
# Visual Studio cache files
179+
# files ending in .cache can be ignored
180+
*.[Cc]ache
181+
# but keep track of directories ending in .cache
182+
!*.[Cc]ache/
183+
184+
# Others
185+
ClientBin/
186+
~$*
187+
*~
188+
*.dbmdl
189+
*.dbproj.schemaview
190+
*.pfx
191+
*.publishsettings
192+
node_modules/
193+
orleans.codegen.cs
194+
195+
# RIA/Silverlight projects
196+
Generated_Code/
197+
198+
# Backup & report files from converting an old project file
199+
# to a newer Visual Studio version. Backup files are not needed,
200+
# because we have git ;-)
201+
_UpgradeReport_Files/
202+
Backup*/
203+
UpgradeLog*.XML
204+
UpgradeLog*.htm
205+
206+
# SQL Server files
207+
*.mdf
208+
*.ldf
209+
210+
# Business Intelligence projects
211+
*.rdl.data
212+
*.bim.layout
213+
*.bim_*.settings
214+
215+
# Microsoft Fakes
216+
FakesAssemblies/
217+
218+
# GhostDoc plugin setting file
219+
*.GhostDoc.xml
220+
221+
# Node.js Tools for Visual Studio
222+
.ntvs_analysis.dat
223+
224+
# Visual Studio 6 build log
225+
*.plg
226+
227+
# Visual Studio 6 workspace options file
228+
*.opt
229+
230+
# Visual Studio LightSwitch build output
231+
**/*.HTMLClient/GeneratedArtifacts
232+
**/*.DesktopClient/GeneratedArtifacts
233+
**/*.DesktopClient/ModelManifest.xml
234+
**/*.Server/GeneratedArtifacts
235+
**/*.Server/ModelManifest.xml
236+
_Pvt_Extensions
237+
238+
# Paket dependency manager
239+
.paket/paket.exe
240+
241+
# FAKE - F# Make
242+
.fake/
243+
244+
/src/CodeCoverage/OpenCover.4.6.519
245+
/src/test-results.xml

Diff for: README.md

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Lazy Elephant #
2+
3+
Lazy Elephant defines a simple template syntax used by the application to generate a full data access layer for PostgreSQL using PostgreSQL conventions for tables and C# conventions for classes.
4+
5+
For each Elephant template we generate:
6+
7+
+ A create table statement in PostgresSQL
8+
+ A C# POCO representing the data class
9+
+ A C# repository containing async methods to create, retrieve, update and delete the data.
10+
11+
Unlike migrations in Entity Framework, Lazy Elephant gives you full control over the resulting code and SQL, it is simply designed to save you time defining the classes needed for data access in C# and the SQL for PostgreSQL.
12+
13+
## Elephant Templates ##
14+
15+
The format of the template is close to C# style syntax with terse additions to define PostgreSQL attributes for the columns.
16+
17+
Apart from the column name field the entire template is case insensitive.
18+
19+
An empty table and class is defined as:
20+
21+
Name {}
22+
23+
This will generate the following C# class:
24+
25+
public class Name {}
26+
27+
We can then add columns/properties in the form:
28+
29+
columnName data_type [attributes, ...],
30+
31+
For example:
32+
33+
sales.customer { id Guid pk ag,
34+
name string uq,
35+
createdDate DateTime df [now],
36+
age int null,
37+
}
38+
39+
There are quite a few new concepts here, the resulting C# class would be:
40+
41+
public class Customer
42+
{
43+
public Guid Id { get; set; }
44+
45+
public string Name { get; set; }
46+
47+
public DateTime CreatedDate { get; set; }
48+
49+
public int? Age { get; set; }
50+
}
51+
52+
The corresponding SQL script would be:
53+
54+
CREATE TABLE sales.customer (
55+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
56+
name TEXT NOT NULL UNIQUE,
57+
created_date TIMESTAMP NOT NULL DEFAULT NOW(),
58+
age INT4
59+
);
60+
61+
### Table Schema ###
62+
63+
By default tables are created in the PostgreSQL schema `public` however the schema can be specified in the form `schema.table` in the Elephant template. In the example above the schema would be `sales` and the table name would be `customer`.
64+
65+
### Data Types ###
66+
67+
The following C# data types are currently supported:
68+
69+
+ Guid
70+
+ string
71+
+ DateTime
72+
+ bool
73+
+ short
74+
+ int
75+
+ long
76+
+ float
77+
+ double
78+
+ decimal
79+
+ TimeSpan
80+
+ byte[]
81+
82+
The data type is case insensitive.
83+
84+
### Primary Key ###
85+
86+
A column is indicated to be a primary key using the `pk` token. Only `string`, `guid` and `int` columns may be primary keys at the moment.
87+
88+
### Auto-Generate ###
89+
90+
A primary key column of the type `int` or `guid` may be set to use autogenerated values using the `ag` token. This will use the Postgres `SERIAL` type for `int` and `DEFAULT uuid_generate_v4()` for `guid`.
91+
92+
### Default ###
93+
94+
Columns may use default values for insertion by specifying a value in brackets following the `df` token. The valid values for the default for a `datetime` column are `[now]` and `[utcnow]`.
95+
96+
### Nullability ###
97+
98+
Good schema design generally avoids nullable columns, to make the templates shorter the column is assumed to be not null unless the `null` token is specified. Primary keys are always non-null in Postgres. For value types in C# the presence of the `null` token causes the type to be a nullable type `Nullable<T>`/`T?`.
99+
100+
### Unique ###
101+
102+
A `UNIQUE` constraint may be added to the column by specifying the `uq` token. Primary keys are unique by default.
103+
104+
## Repository ##
105+
106+
Rather than using any magic for its data access layer LazyElephant generates simple SQL statements in valid C#.
107+
108+
For the earlier template:
109+
110+
sales.customer { id Guid pk ag,
111+
name string uq,
112+
createdDate DateTime df [now],
113+
age int null,
114+
}
115+
116+
The repository generated contains the following methods:
117+
118+
public async Task<Customer> Create(Customer customer);

Diff for: src/LazyElephant.Tests/Data/1/Class.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace PostPig.DataAccess.Florp
4+
{
5+
public class Task
6+
{
7+
public Guid Id { get; set; }
8+
9+
public string Name { get; set; }
10+
11+
public string Description { get; set; }
12+
13+
public DateTime Created { get; set; }
14+
15+
public Guid UserId { get; set; }
16+
}
17+
}

0 commit comments

Comments
 (0)