mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:07:34 +00:00
LibSQL: Added 'nullable' and 'default value' option to ColumnDef
These are standard SQL concepts which columns should be aware of.
This commit is contained in:
parent
b74721e604
commit
230118c4b2
2 changed files with 14 additions and 0 deletions
|
@ -46,6 +46,7 @@ ColumnDef::ColumnDef(Relation* parent, size_t column_number, String name, SQLTyp
|
|||
: Relation(move(name), parent)
|
||||
, m_index(column_number)
|
||||
, m_type(sql_type)
|
||||
, m_default(Value(sql_type))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -59,6 +60,12 @@ Key ColumnDef::key() const
|
|||
return key;
|
||||
}
|
||||
|
||||
void ColumnDef::set_default_value(const Value& default_value)
|
||||
{
|
||||
VERIFY(default_value.type() == type());
|
||||
m_default = default_value;
|
||||
}
|
||||
|
||||
Key ColumnDef::make_key(TableDef const& table_def)
|
||||
{
|
||||
Key key(index_def());
|
||||
|
|
|
@ -74,6 +74,11 @@ public:
|
|||
Key key() const override;
|
||||
SQLType type() const { return m_type; }
|
||||
size_t column_number() const { return m_index; }
|
||||
void set_not_null(bool can_not_be_null) { m_not_null = can_not_be_null; }
|
||||
bool not_null() const { return m_not_null; }
|
||||
void set_default_value(Value const& default_value);
|
||||
Value const& default_value() const { return m_default; }
|
||||
|
||||
static NonnullRefPtr<IndexDef> index_def();
|
||||
static Key make_key(TableDef const&);
|
||||
|
||||
|
@ -83,6 +88,8 @@ protected:
|
|||
private:
|
||||
size_t m_index;
|
||||
SQLType m_type { SQLType::Text };
|
||||
bool m_not_null { false };
|
||||
Value m_default;
|
||||
};
|
||||
|
||||
class KeyPartDef : public ColumnDef {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue