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

Lang 9.0. Doc fixes. #69

Merged
merged 4 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
82 changes: 42 additions & 40 deletions Postgrest/Attributes/ColumnAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
using System;
using System.Runtime.CompilerServices;
using Newtonsoft.Json;
namespace Postgrest.Attributes
{

namespace Postgrest.Attributes;
/// <summary>
/// Used to map a C# property to a Postgrest Column.
/// </summary>
/// <example>
/// <code>
/// class User : BaseModel {
/// [ColumnName("firstName")]
/// public string FirstName {get; set;}
/// }
/// </code>
/// </example>
[AttributeUsage(AttributeTargets.Property)]
public class ColumnAttribute : Attribute
{
/// <summary>
/// The name in postgres of this column.
/// </summary>
public string ColumnName { get; }

/// <summary>
/// Used to map a C# property to a Postgrest Column.
/// </summary>
/// <example>
/// <code>
/// class User : BaseModel {
/// [ColumnName("firstName")]
/// public string FirstName {get; set;}
/// }
/// </code>
/// </example>
[AttributeUsage(AttributeTargets.Property)]
public class ColumnAttribute : Attribute
{
/// <summary>
/// The name in postgres of this column.
/// </summary>
public string ColumnName { get; }

/// <summary>
/// Specifies what should be serialized in the event this column's value is NULL
/// </summary>
public NullValueHandling NullValueHandling { get; set; }
/// <summary>
/// Specifies what should be serialized in the event this column's value is NULL
/// </summary>
public NullValueHandling NullValueHandling { get; set; }

/// <summary>
/// If the performed query is an Insert or Upsert, should this value be ignored?
/// </summary>
public bool IgnoreOnInsert { get; }
/// <summary>
/// If the performed query is an Insert or Upsert, should this value be ignored?
/// </summary>
public bool IgnoreOnInsert { get; }

/// <summary>
/// If the performed query is an Update, should this value be ignored?
/// </summary>
public bool IgnoreOnUpdate { get; }
/// <summary>
/// If the performed query is an Update, should this value be ignored?
/// </summary>
public bool IgnoreOnUpdate { get; }

public ColumnAttribute([CallerMemberName] string? columnName = null, NullValueHandling nullValueHandling = NullValueHandling.Include, bool ignoreOnInsert = false, bool ignoreOnUpdate = false)
{
ColumnName = columnName!; // Will either be user specified or given by runtime compiler.
NullValueHandling = nullValueHandling;
IgnoreOnInsert = ignoreOnInsert;
IgnoreOnUpdate = ignoreOnUpdate;
}
}
/// <inheritdoc />
public ColumnAttribute([CallerMemberName] string? columnName = null, NullValueHandling nullValueHandling = NullValueHandling.Include, bool ignoreOnInsert = false, bool ignoreOnUpdate = false)
{
ColumnName = columnName!; // Will either be user specified or given by runtime compiler.
NullValueHandling = nullValueHandling;
IgnoreOnInsert = ignoreOnInsert;
IgnoreOnUpdate = ignoreOnUpdate;
}
}
}
55 changes: 29 additions & 26 deletions Postgrest/Attributes/PrimaryKeyAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
using System;
using System.Runtime.CompilerServices;
#pragma warning disable CS1591

namespace Postgrest.Attributes;

/// <summary>
/// Used to map a C# property to a Postgrest PrimaryKey.
/// </summary>
/// <example>
/// <code>
/// class User : BaseModel {
/// [PrimaryKey("id")]
/// public string Id {get; set;}
/// }
/// </code>
/// </example>
[AttributeUsage(AttributeTargets.Property)]
public class PrimaryKeyAttribute : Attribute
namespace Postgrest.Attributes
{
public string ColumnName { get; }

/// <summary>
/// Would be set to false in the event that the database handles the generation of this property.
/// </summary>
public bool ShouldInsert { get; }
/// <summary>
/// Used to map a C# property to a Postgrest PrimaryKey.
/// </summary>
/// <example>
/// <code>
/// class User : BaseModel {
/// [PrimaryKey("id")]
/// public string Id {get; set;}
/// }
/// </code>
/// </example>
[AttributeUsage(AttributeTargets.Property)]
public class PrimaryKeyAttribute : Attribute
{
public string ColumnName { get; }

/// <summary>
/// Would be set to false in the event that the database handles the generation of this property.
/// </summary>
public bool ShouldInsert { get; }

public PrimaryKeyAttribute([CallerMemberName] string? columnName = null, bool shouldInsert = false)
{
ColumnName = columnName!; // Either given by user or specified by runtime compiler.
ShouldInsert = shouldInsert;
}
}
public PrimaryKeyAttribute([CallerMemberName] string? columnName = null, bool shouldInsert = false)
{
ColumnName = columnName!; // Either given by user or specified by runtime compiler.
ShouldInsert = shouldInsert;
}
}
}
Loading