mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-10-26 18:41:18 +00:00
43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
// TableSchema.cs
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// SPDX-FileCopyrightText: 2025 Catswords OSS and WelsonJS Contributors
|
|
// https://github.com/gnh1201/welsonjs
|
|
//
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace WelsonJS.Launcher.Storage
|
|
{
|
|
public class Schema
|
|
{
|
|
public string TableName { get; set; }
|
|
public List<Column> Columns { get; set; }
|
|
public Column PrimaryKey
|
|
{
|
|
get
|
|
{
|
|
return Columns.Find(c => c.IsPrimaryKey) ?? null;
|
|
}
|
|
}
|
|
|
|
public Schema(string tableName, List<Column> columns)
|
|
{
|
|
TableName = tableName;
|
|
Columns = columns ?? new List<Column>();
|
|
}
|
|
|
|
public void SetPrimaryKey(string columnName)
|
|
{
|
|
Column column = Columns.Find(c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase));
|
|
if (column != null)
|
|
{
|
|
column.IsPrimaryKey = true;
|
|
}
|
|
else
|
|
{
|
|
throw new ArgumentException($"Column '{columnName}' does not exist in schema '{TableName}'.");
|
|
}
|
|
}
|
|
}
|
|
}
|