Skip to content

Commit

Permalink
First project commit
Browse files Browse the repository at this point in the history
  • Loading branch information
developer82 committed Feb 13, 2015
1 parent b2e234c commit c444ebe
Show file tree
Hide file tree
Showing 39 changed files with 2,174 additions and 0 deletions.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Ophir Oren

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

40 changes: 40 additions & 0 deletions Poco.Sql.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31206.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Poco.Sql", "Poco.Sql\Poco.Sql.csproj", "{B8DC5366-5CA3-474A-8229-00E8C827068F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PocoSql.Demo", "PocoSql.Demo\PocoSql.Demo.csproj", "{58A8C3E6-47FA-43C0-9C2E-756DAF4C8A09}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PocoSql.Test.Models", "PocoSql.Test.Models\PocoSql.Test.Models.csproj", "{69408406-7690-4EC4-B972-F736EA558542}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PocoSql.UnitTests", "PocoSql.UnitTests\PocoSql.UnitTests.csproj", "{18616522-DD06-40F5-8578-5D697F9059D1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B8DC5366-5CA3-474A-8229-00E8C827068F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B8DC5366-5CA3-474A-8229-00E8C827068F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8DC5366-5CA3-474A-8229-00E8C827068F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8DC5366-5CA3-474A-8229-00E8C827068F}.Release|Any CPU.Build.0 = Release|Any CPU
{58A8C3E6-47FA-43C0-9C2E-756DAF4C8A09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58A8C3E6-47FA-43C0-9C2E-756DAF4C8A09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58A8C3E6-47FA-43C0-9C2E-756DAF4C8A09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58A8C3E6-47FA-43C0-9C2E-756DAF4C8A09}.Release|Any CPU.Build.0 = Release|Any CPU
{69408406-7690-4EC4-B972-F736EA558542}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{69408406-7690-4EC4-B972-F736EA558542}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69408406-7690-4EC4-B972-F736EA558542}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69408406-7690-4EC4-B972-F736EA558542}.Release|Any CPU.Build.0 = Release|Any CPU
{18616522-DD06-40F5-8578-5D697F9059D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{18616522-DD06-40F5-8578-5D697F9059D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18616522-DD06-40F5-8578-5D697F9059D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18616522-DD06-40F5-8578-5D697F9059D1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions PocoSql.Demo/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
68 changes: 68 additions & 0 deletions PocoSql.Demo/PocoSql.Demo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{58A8C3E6-47FA-43C0-9C2E-756DAF4C8A09}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PocoSql.Demo</RootNamespace>
<AssemblyName>PocoSql.Demo</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Poco.Sql\Poco.Sql.csproj">
<Project>{b8dc5366-5ca3-474a-8229-00e8c827068f}</Project>
<Name>Poco.Sql</Name>
</ProjectReference>
<ProjectReference Include="..\PocoSql.Test.Models\PocoSql.Test.Models.csproj">
<Project>{69408406-7690-4ec4-b972-f736ea558542}</Project>
<Name>PocoSql.Test.Models</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
115 changes: 115 additions & 0 deletions PocoSql.Demo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using Poco.Sql;
using Poco.Sql.Exceptions;
using Poco.Sql.Extensions;
using PocoSql.Test.Models;
using PocoSql.Test.Models.Mappings;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PocoSql.Demo
{
class Program
{
static void Main(string[] args)
{
// TODO: Bug: Values are injected in WHERE statement when they should be parameterized

Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine(@" ____ __ ___ __ ____ __ __ ");
Console.WriteLine(@"( _ \ / \ / __)/ \ / ___) / \ ( ) ");
Console.WriteLine(@" ) __/( O )( (__( O )_ \___ \( O )/ (_/\");
Console.WriteLine(@"(__) \__/ \___)\__/(_)(____/ \__\)\____/");
Console.WriteLine("");
Console.WriteLine("Poco.Sql");
Console.WriteLine("Written by Ophir Oren. All rights reserved © Ophir Oren 2015.");
Console.WriteLine("Released under MIT license.");
Console.WriteLine("http://www.webe.co.il");
Console.WriteLine("");
Console.ResetColor();

QueryBuilder.Configuration.PluralizeTableNames = true; // for example: for object User the table name will be Users
QueryBuilder.Configuration.StoredProceduresPrefix = "stp_";
//QueryBuilder.Configuration.Comment = true;
//QueryBuilder.Configuration.InjectValuesToQueies = true;
//QueryBuilder.Configuration.SelectFullGraphAsDefault = true; // TODO: not completed yet

// Add mappings
QueryBuilder.AddStaticMapping(new UserMap());
QueryBuilder.AddStaticMapping(new OrderMap());
QueryBuilder.AddStaticMapping(new VUserMap());

string sql;

var user = new User()
{
UserId = 1,
Age = 32,
Name = "Ophir",
Birthday = new DateTime(1982, 5, 6)
};

var vuser = new VUser()
{
UserId = 1,
Age = 32,
Name = "Ophir",
Birthday = new DateTime(1982, 5, 6)
};

var orders = new List<Order>()
{
new Order() { UserId = 1, User = user, ItemName = "Item 1", OrderId = 1, Quantity = 5 },
new Order() { UserId = 1, User = user, ItemName = "Item 2", OrderId = 1, Quantity = 4 },
new Order() { UserId = 1, User = user, ItemName = "Item 3", OrderId = 1, Quantity = 3 },
new Order() { UserId = 1, User = user, ItemName = "Item 4", OrderId = 1, Quantity = 2 },
new Order() { UserId = 1, User = user, ItemName = "Item 5", OrderId = 1, Quantity = 1 }
};

sql = user.PocoSql().Select().ToString();
Console.WriteLine("user.PocoSql().Select()");
Console.WriteLine(sql + Environment.NewLine);

sql = user.PocoSql().Insert().ToString();
Console.WriteLine("user.PocoSql().Insert()");
Console.WriteLine(sql + Environment.NewLine);

sql = user.PocoSql().Update().ToString();
Console.WriteLine("user.PocoSql().Update()");
Console.WriteLine(sql + Environment.NewLine);

sql = user.PocoSql().Delete().ToString();
Console.WriteLine("user.PocoSql().Delete()");
Console.WriteLine(sql + Environment.NewLine);

sql = vuser.PocoSql().Select().ToString();
Console.WriteLine("vuser.PocoSql().Select()");
Console.WriteLine(sql + Environment.NewLine);

sql = vuser.PocoSql().Select().Where<VUser>(u => u.UserId == 1).ToString();
Console.WriteLine("vuser.PocoSql().Select()");
Console.WriteLine(sql + Environment.NewLine);

sql = vuser.PocoSql().Select().Where<VUser>(u => u.Birthday > DateTime.Now.AddYears(-50) && u.Birthday < DateTime.Now).ToString(); // TODO: this query is not performing correctly
Console.WriteLine("vuser.PocoSql().Select()");
Console.WriteLine(sql + Environment.NewLine);

try
{
sql = vuser.PocoSql().Insert().ToString();
}
catch(CantUpdateVirtualException ex)
{
Console.WriteLine("The following exception is expected");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex.Message);
Console.ResetColor();
}

Console.ReadLine();
}
}
}
36 changes: 36 additions & 0 deletions PocoSql.Demo/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PocoSql.Demo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PocoSql.Demo")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4f535f97-f083-4943-bbae-405fc2e6e8b6")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
25 changes: 25 additions & 0 deletions PocoSql.Test.Models/Mappings/OrderMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Poco.Sql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PocoSql.Test.Models.Mappings
{
public class OrderMap : PocoSqlMapping<Order>
{
public OrderMap()
{
// Primary Key
this.HasKey(t => t.OrderId);

// Table & Column Mappings
this.ToTable("Orders");

this.HasOptional(t => t.User)
.WithMany(t => t.Orders)
.HasForeignKey(d => d.UserId);
}
}
}
36 changes: 36 additions & 0 deletions PocoSql.Test.Models/Mappings/UserMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Poco.Sql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PocoSql.Test.Models.Mappings
{
public class UserMap : PocoSqlMapping<User>
{
public UserMap()
{
// Primary Key
this.HasKey(t => t.UserId).AutoGenerated();

// Properties
this.Property(t => t.Name)
.IsRequired()
.HasMaxLength(20);

// Table & Column Mappings
this.ToTable("Users");
this.Property(t => t.Name).HasColumnName("Name");
this.Property(t => t.Birthday).HasColumnName("DateOfBirth");
this.Property(t => t.Age).Ignore();

/*
this.MapToStoredProcedures(s =>
{
s.Update().IncludeExecution().IncludeParameters(); //TODO: BUG - why does the result includes where caluse??? ---> exec stp_User_UpdateAge = @Age, Name = @Name, Birthday = @Birthday where UserId= 1;
});
*/
}
}
}
20 changes: 20 additions & 0 deletions PocoSql.Test.Models/Mappings/VUserMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Poco.Sql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PocoSql.Test.Models.Mappings
{
public class VUserMap : PocoSqlMapping<VUser>
{
public VUserMap()
{
// Primary Key
this.HasKey(t => t.UserId);

this.IsVirtual();
}
}
}
17 changes: 17 additions & 0 deletions PocoSql.Test.Models/Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PocoSql.Test.Models
{
public class Order
{
public int OrderId { get; set; }
public int UserId { get; set; }
public string ItemName { get; set; }
public int Quantity { get; set; }
public User User { get; set; }
}
}
Loading

0 comments on commit c444ebe

Please sign in to comment.