Skip to content

Commit

Permalink
Supports upstream relations
Browse files Browse the repository at this point in the history
I am trying to create an index for the column that maps to the upstream relation.
  • Loading branch information
mk3008 committed May 6, 2024
1 parent f2a8b04 commit 62bfb85
Show file tree
Hide file tree
Showing 28 changed files with 653 additions and 557 deletions.
10 changes: 1 addition & 9 deletions src/Carbunql/Analysis/Parser/ConstraintParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ namespace Carbunql.Analysis;

public static class ConstraintParser
{
//public static IConstraint Parse(string text)
//{
// var r = new SqlTokenReader(text);
// var q = Parse(r);
// return q;
//}

public static IConstraint Parse(ITable t, ITokenReader r)
{
var token = r.Read();
Expand All @@ -26,10 +19,9 @@ public static IConstraint Parse(ITable t, ITokenReader r)
if (token.IsEqualNoCase("primary key"))
{
var columns = ArrayParser.Parse(r);
return new PrimaryKeyConstraint(t)
return new PrimaryKeyConstraint(t, columns)
{
ConstraintName = name,
ColumnNames = columns
};
}

Expand Down
22 changes: 21 additions & 1 deletion src/Carbunql/Annotations/AutoNumberDefinitionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,33 @@

namespace Carbunql.Annotations;

/// <summary>
/// Factory class for creating auto number definitions.
/// </summary>
public static class AutoNumberDefinitionFactory
{
/// <summary>
/// Tries to create an auto number definition for the specified type <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">The type of class for which to create the auto number definition.</typeparam>
/// <param name="autoNumberDefinition">When this method returns, contains the auto number definition if successful, or the default value if unsuccessful.</param>
/// <returns>True if the auto number definition is successfully created; otherwise, false.</returns>
public static bool TryCreate<T>([MaybeNullWhen(false)] out ValueBase autoNumberDefinition)
{
return TryCreate(typeof(T), out autoNumberDefinition);
}

/// <summary>
/// Tries to create an auto number definition for the specified type.
/// </summary>
/// <param name="type">The type of class for which to create the auto number definition.</param>
/// <param name="autoNumberDefinition">When this method returns, contains the auto number definition if successful, or the default value if unsuccessful.</param>
/// <returns>True if the auto number definition is successfully created; otherwise, false.</returns>
public static bool TryCreate(Type type, [MaybeNullWhen(false)] out ValueBase autoNumberDefinition)
{
autoNumberDefinition = default;

var atr = (TableAttribute?)Attribute.GetCustomAttribute(typeof(T), typeof(TableAttribute));
var atr = (TableAttribute?)Attribute.GetCustomAttribute(type, typeof(TableAttribute));
var def = string.Empty;

if (atr != null)
Expand Down
40 changes: 0 additions & 40 deletions src/Carbunql/Annotations/ClassTableDefinitionClause.cs

This file was deleted.

66 changes: 40 additions & 26 deletions src/Carbunql/Annotations/ColumnAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,74 @@
namespace Carbunql.Annotations;

/// <summary>
/// Attribute used to define metadata for a column in a database table.
/// </summary>
[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
public class ColumnAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the ColumnAttribute class.
/// </summary>
public ColumnAttribute()
{
}

/// <summary>
/// Initializes a new instance of the ColumnAttribute class with the specified column type.
/// </summary>
/// <param name="columnType">The type of the column.</param>
public ColumnAttribute(string columnType)
{
ColumnType = columnType;
}

/// <summary>
/// Gets or sets the name of the column.
/// </summary>
public string ColumnName { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the type of the column.
/// </summary>
public string ColumnType { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the type of the related column, if any.
/// </summary>
public string RelationColumnType { get; set; } = string.Empty;

/// <summary>
/// Gets or sets a value indicating whether the column is auto-incremented.
/// </summary>
public bool IsAutoNumber { get; set; } = false;

/// <summary>
/// Gets or sets a value indicating whether the column allows null values.
/// </summary>
public bool IsNullable { get; set; } = false;

/// <summary>
/// Gets or sets the definition for the auto-incremented column.
/// </summary>
public string AutoNumberDefinition { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the default value for the column.
/// </summary>
public string DefaultValue { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the comment associated with the column.
/// </summary>
public string Comment { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the command to retrieve a timestamp value.
/// </summary>
public string TimestampCommand { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the special type of the column, if any.
/// </summary>
public SpecialColumn SpecialColumn { get; set; } = SpecialColumn.None;

//public PropertyColumnDefinition ToDefinition(ITable t, PropertyInfo prop)
//{
// var columnName = (!string.IsNullOrEmpty(ColumnName)) ? ColumnName : prop.Name.ToSnakeCase();
// var columnType = (!string.IsNullOrEmpty(ColumnType)) ? ColumnType : DbmsConfiguration.ToDbType(prop.PropertyType);
// var relationColumnType = (!string.IsNullOrEmpty(RelationColumnType)) ? RelationColumnType : DbmsConfiguration.ToDbType(prop.PropertyType);

// var c = new PropertyColumnDefinition(t, columnName, columnType, prop.Name)
// {
// RelationColumnType = relationColumnType,
// Comment = Comment,
// IsAutoNumber = IsAutoNumber,
// SpecialColumn = SpecialColumn,
// IsNullable = prop.IsNullable(),
// };

// if (IsAutoNumber && !string.IsNullOrEmpty(AutoNumberDefinition))
// {
// c.DefaultValue = ValueParser.Parse(AutoNumberDefinition);
// }
// if (!string.IsNullOrEmpty(DefaultValue))
// {
// c.DefaultValue = ValueParser.Parse(DefaultValue);
// }
// return c;
//}
}
Loading

0 comments on commit 62bfb85

Please sign in to comment.