-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathColumnJSON.cs
More file actions
37 lines (31 loc) · 1022 Bytes
/
ColumnJSON.cs
File metadata and controls
37 lines (31 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
namespace PowerSync.Common.DB.Schema;
public enum ColumnType
{
Text,
Integer,
Real,
/// <summary>
/// <para>Infers the column type based on the associated property's PropertyType.</para>
/// <para>**NB:** `ColumnType.Inferred` can only be used when using the schema attributes syntax.</para>
/// </summary>
Inferred
}
class ColumnJSONOptions(string Name, ColumnType? Type)
{
public string Name { get; set; } = Name;
public ColumnType? Type { get; set; } = Type;
}
class ColumnJSON(ColumnJSONOptions options)
{
public string Name { get; set; } = options.Name;
public ColumnType Type { get; set; } = options.Type ?? ColumnType.Text;
public object ToJSONObject()
{
if (Type == ColumnType.Inferred) throw new InvalidOperationException("Attempted to serialise Inferred column. ColumnType.Inferred is only valid as an argument to ColumnAttribute.");
return new
{
name = Name,
type = Type.ToString()
};
}
}