Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add create table #680

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6302c9e
Add Support for Create Table
Jun 27, 2023
c2632d0
Create Table Query making is started
Jun 27, 2023
31b7d97
change the type of create table return type
Jun 27, 2023
1959d03
Create Table Class for Query is Added
Jun 27, 2023
0c72c03
Adding sql server compiler for create table
Jun 27, 2023
0b9f44b
sql server compiler is now completed
Jun 27, 2023
762f5d6
Debugging sql server compiler has been started
Jun 27, 2023
2b8b9c9
sql server compiler has been corrected but some small changes needs t…
Jun 27, 2023
5aa0cb4
Correct DbType for creating table in db
Jun 30, 2023
6dea909
Correct and refactor create table
Jun 30, 2023
6fd4137
Create Table in all dbs was ok
Jun 30, 2023
f32afe2
Add Sqlite for creating table
Jun 30, 2023
f479f94
Refactor and fix the type conversion
Jun 30, 2023
f9a5c0f
fix some bugs
Jul 1, 2023
ac56c01
fix bug in creating table in postgresql
Jul 1, 2023
05c882e
oracle create query add ON COMMIT PRESERVE ROWS
Jul 2, 2023
9f85db9
revert the last change
Jul 2, 2023
97d87a4
change the structure of creating table query
AlirezaEiji191379 Jul 3, 2023
c50860e
Create Table Fillers and Formatters
AlirezaEiji191379 Jul 3, 2023
f546968
Add DI to SqlKata
AlirezaEiji191379 Jul 3, 2023
f6e3cdc
change the versions
AlirezaEiji191379 Jul 3, 2023
0a1b8b5
di managing
AlirezaEiji191379 Jul 3, 2023
e2e3ce4
Create Table is now under test
AlirezaEiji191379 Jul 3, 2023
907b2ca
bug fix for oracle
AlirezaEiji191379 Jul 3, 2023
4a99fe0
on commit preserve rows was added success fully for oracle create table
AlirezaEiji191379 Jul 3, 2023
acdccff
add hint and collation for table creation
AlirezaEiji191379 Jul 4, 2023
dd7cbd3
add collate to CreateTableColumn
Jul 4, 2023
e4706a7
create CreateTableAsClause.cs
Jul 4, 2023
fe3247d
Create table as is now completed and under test
AlirezaEiji191379 Jul 4, 2023
298428e
Add DropTable
AlirezaEiji191379 Jul 4, 2023
aaa8583
db column and format was changed
AlirezaEiji191379 Jul 5, 2023
20275f0
correct create table as format
Jul 5, 2023
0fe20e3
Add Select Into Query
Jul 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add collate to CreateTableColumn
  • Loading branch information
Reza Mehtari committed Jul 4, 2023
commit dd7cbd313263cab2dffc4777413aaa4cb994ee29
2 changes: 1 addition & 1 deletion Program/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void Main(string[] args)
var compilerProvider = provider.GetRequiredService<ICompilerProvider>();
var compiler = compilerProvider.CreateCompiler(DataSource.Oracle);

var query = new Query("Users").CreateTable(new List<TableColumnDefenitionDto>()
var query = new Query("Users").CreateTable(new List<TableColumnDefinitionDto>()
{
new()
{
Expand Down
4 changes: 3 additions & 1 deletion QueryBuilder/Clauses/ColumnClause.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class CreateTableColumn : AbstractClause
public bool IsUnique { get; set; }
public bool IsIdentity { get; set; }
public bool IsAutoIncrement { get; set; }
public string Collate { get; set; }
public override AbstractClause Clone()
{
return new CreateTableColumn
Expand All @@ -53,6 +54,7 @@ public override AbstractClause Clone()
IsUnique= IsUnique,
IsIdentity= IsIdentity,
IsNullable= IsNullable,
Collate = Collate
};
}
}
Expand Down Expand Up @@ -114,7 +116,7 @@ public override AbstractClause Clone()
public class AggregatedColumn : AbstractColumn
{
/// <summary>
/// Gets or sets the a query that used to filter the data,
/// Gets or sets the a query that used to filter the data,
/// the compiler will consider only the `Where` clause.
/// </summary>
/// <value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ public string CompileCreateTableColumns(List<CreateTableColumn> createTableColum
{
throw new AutoIncrementOrIdentityExceededException("table can not have more than one auto increment or identity column");
}
foreach (var columnCluase in createTableColumnClauses)
foreach (var columnClause in createTableColumnClauses)
{
var nullOrNot = columnCluase.IsNullable ? "NULL " : "NOT NULL ";
if (columnCluase.IsIdentity || columnCluase.IsAutoIncrement)
var nullOrNot = columnClause.IsNullable ? "NULL " : "NOT NULL ";
var collate = columnClause.Collate == null ? "" : $"Collate {columnClause.Collate}";
if (columnClause.IsIdentity || columnClause.IsAutoIncrement)
{
queryString.Append($"{columnCluase.ColumnName} {columnCluase.ColumnDbType.GetDBType()} {_sqlCommandUtil.AutoIncrementIdentityCommandGenerator()},\n");
queryString.Append($"{columnClause.ColumnName} {columnClause.ColumnDbType.GetDBType()} {collate} {_sqlCommandUtil.AutoIncrementIdentityCommandGenerator()},\n");
continue;
}
queryString.Append($"{columnCluase.ColumnName} {columnCluase.ColumnDbType.GetDBType()} {nullOrNot},\n");
queryString.Append($"{columnClause.ColumnName} {columnClause.ColumnDbType.GetDBType()} {collate} {nullOrNot},\n");
}

return queryString.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SqlKata.Contract.CreateTable
{
public class TableColumnDefenitionDto
public class TableColumnDefinitionDto
{
public string ColumnName { get; set; }
public BaseDBColumn ColumnDbType { get; set; }
Expand All @@ -11,5 +11,6 @@ public class TableColumnDefenitionDto
public bool IsUnique { get; set; }
public bool IsIdentity { get; set; }
public bool IsAutoIncrement { get; set; }
public string Collate { get; set; }
}
}
5 changes: 3 additions & 2 deletions QueryBuilder/Query.CreateTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SqlKata
{
public partial class Query
{
public Query CreateTable(IEnumerable<TableColumnDefenitionDto> columns,TableType tableType = TableType.Permanent,CreateDbTableExtension createDbTableExtension = null)
public Query CreateTable(IEnumerable<TableColumnDefinitionDto> columns,TableType tableType = TableType.Permanent,CreateDbTableExtension createDbTableExtension = null)
{
Method = "CreateTable";

Expand All @@ -29,7 +29,8 @@ public Query CreateTable(IEnumerable<TableColumnDefenitionDto> columns,TableType
IsUnique = column.IsUnique,
IsPrimaryKey = column.IsPrimaryKey,
IsAutoIncrement = column.IsAutoIncrement,
IsIdentity = column.IsIdentity
IsIdentity = column.IsIdentity,
Collate = column.Collate
});
});

Expand Down