GithubHelp home page GithubHelp logo

codefork / fluentdatabase Goto Github PK

View Code? Open in Web Editor NEW

This project forked from joshclose/fluentdatabase

0.0 2.0 0.0 136 KB

A .NET library created in C# to fluently create any type of database

License: Microsoft Public License

C# 100.00%

fluentdatabase's Introduction

FluentDatabase is a library to fluently create a number of different database types.

Currently supported databases are:

  • Access
  • Firebird
  • MySQL
  • Oracle
  • PostgreSQL
  • SQLite
  • SQLServer

Example:


DatabaseFactory.Create( databaseType )
	.WithName( "Business" )
	.UsingSchema( "Test" )
	.HasTable(
	table => table
	         	.WithName( "Companies" )
	         	.HasColumn(
	         	column => column.WithName( "Id" ).OfType( SqlDbType.Int ).IsAutoIncrementing()
	         	          	.HasConstraint( constraint => constraint.OfType( ConstraintType.NotNull ) )
	         	          	.HasConstraint(
	         	          	constraint => constraint.OfType( ConstraintType.PrimaryKey ).WithName( "PK_Companies_Id" ) )
	         	)
	         	.HasColumn(
	         	column => column.WithName( "Name" ).OfType( SqlDbType.NVarChar, 100 )
	         	          	.HasConstraint( constraint => constraint.OfType( ConstraintType.NotNull ) )
	         	)
	)
	.HasTable(
	table => table
	         	.WithName( "Employees" )
	         	.HasColumn(
	         	column => column.WithName( "Id" ).OfType( SqlDbType.Int ).IsAutoIncrementing()
	         	          	.HasConstraint( constraint => constraint.OfType( ConstraintType.NotNull ) )
	         	          	.HasConstraint(
	         	          	constraint => constraint.OfType( ConstraintType.PrimaryKey ).WithName( "PK_Employees_Id" ) )
	         	)
	         	.HasColumn(
	         	column => column.WithName( "CompanyId" ).OfType( SqlDbType.Int )
	         	          	.HasConstraint( constraint => constraint.OfType( ConstraintType.NotNull ) )
	         	          	.HasConstraint(
	         	          	constraint =>
	         	          	constraint.WithName( "FK_Employees_CompanyId" ).OfType( ConstraintType.ForeignKey ).HasReferenceTo( "Companies", "Id" ) )
	         	)
	         	.HasColumn(
	         	column => column.WithName( "Name" ).OfType( SqlDbType.NVarChar, 50 )
	         	          	.HasConstraint( constraint => constraint.OfType( ConstraintType.NotNull ) )
	         	)
	         	.HasColumn(
	         	column => column.WithName( "Bio" ).OfType( SqlDbType.NVarChar, ColumnSize.Max )
	         	)
	).Write( writer );

Creates the script:


USE [Business]

CREATE TABLE [Test].[Companies]
(
	[Id] INT IDENTITY NOT NULL CONSTRAINT [PK_Companies_Id] PRIMARY KEY,
	[Name] NVARCHAR ( 100 ) NOT NULL,
)

CREATE TABLE [Test].[Employees]
(
	[Id] INT IDENTITY NOT NULL CONSTRAINT [PK_Employees_Id] PRIMARY KEY,
	[CompanyId] INT NOT NULL CONSTRAINT [FK_Employees_CompanyId] FOREIGN KEY REFERENCES [Test].[Companies] ( [Id] ),
	[Name] NVARCHAR ( 50 ) NOT NULL,
	[Bio] NVARCHAR ( MAX ),
)

fluentdatabase's People

Contributors

joshclose avatar

Watchers

James Cloos avatar Gorel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.