Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
database::orm::field_metadata Class Reference

Metadata for entity fields including constraints and relationships. More...

#include <entity.h>

Collaboration diagram for database::orm::field_metadata:
Collaboration graph

Public Member Functions

 field_metadata (const std::string &name, const std::string &type_name, field_constraint constraints=field_constraint::none, const std::string &index_name="", const std::string &foreign_table="", const std::string &foreign_field="")
 
const std::string & name () const
 
const std::string & type_name () const
 
field_constraint constraints () const
 
const std::string & index_name () const
 
const std::string & foreign_table () const
 
const std::string & foreign_field () const
 
bool is_primary_key () const
 
bool is_not_null () const
 
bool is_unique () const
 
bool is_auto_increment () const
 
bool has_index () const
 
bool is_foreign_key () const
 
bool has_default_now () const
 
std::string to_sql_definition () const
 

Private Attributes

std::string name_
 
std::string type_name_
 
field_constraint constraints_
 
std::string index_name_
 
std::string foreign_table_
 
std::string foreign_field_
 

Detailed Description

Metadata for entity fields including constraints and relationships.

Definition at line 77 of file entity.h.

Constructor & Destructor Documentation

◆ field_metadata()

database::orm::field_metadata::field_metadata ( const std::string & name,
const std::string & type_name,
field_constraint constraints = field_constraint::none,
const std::string & index_name = "",
const std::string & foreign_table = "",
const std::string & foreign_field = "" )
Examples
/home/runner/work/database_system/database_system/database/orm/entity.h.

Definition at line 24 of file entity.cpp.

30 : name_(name)
36 {
37 }
field_constraint constraints_
Definition entity.h:107
const std::string & index_name() const
Definition entity.h:90
field_constraint constraints() const
Definition entity.h:89
const std::string & name() const
Definition entity.h:87
const std::string & type_name() const
Definition entity.h:88
const std::string & foreign_table() const
Definition entity.h:91
const std::string & foreign_field() const
Definition entity.h:92

Member Function Documentation

◆ constraints()

field_constraint database::orm::field_metadata::constraints ( ) const
inline

◆ foreign_field()

const std::string & database::orm::field_metadata::foreign_field ( ) const
inline
Examples
/home/runner/work/database_system/database_system/database/orm/entity.h.

Definition at line 92 of file entity.h.

92{ return foreign_field_; }

References foreign_field_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ foreign_table()

const std::string & database::orm::field_metadata::foreign_table ( ) const
inline
Examples
/home/runner/work/database_system/database_system/database/orm/entity.h.

Definition at line 91 of file entity.h.

91{ return foreign_table_; }

References foreign_table_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ has_default_now()

bool database::orm::field_metadata::has_default_now ( ) const
inline
Examples
/home/runner/work/database_system/database_system/database/orm/entity.h.

Definition at line 100 of file entity.h.

bool has_constraint(field_constraint constraints, field_constraint check)
Definition entity.h:69

References constraints_, database::orm::default_now, and database::orm::has_constraint().

Referenced by TEST_F(), TEST_F(), and to_sql_definition().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ has_index()

bool database::orm::field_metadata::has_index ( ) const
inline
Examples
/home/runner/work/database_system/database_system/database/orm/entity.h.

Definition at line 98 of file entity.h.

References constraints_, database::orm::has_constraint(), and database::orm::index.

Referenced by TEST_F(), and TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ index_name()

const std::string & database::orm::field_metadata::index_name ( ) const
inline
Examples
/home/runner/work/database_system/database_system/database/orm/entity.h.

Definition at line 90 of file entity.h.

90{ return index_name_; }

References index_name_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ is_auto_increment()

bool database::orm::field_metadata::is_auto_increment ( ) const
inline
Examples
/home/runner/work/database_system/database_system/database/orm/entity.h.

Definition at line 97 of file entity.h.

References database::orm::auto_increment, constraints_, and database::orm::has_constraint().

Referenced by TEST_F(), TEST_F(), and to_sql_definition().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_foreign_key()

bool database::orm::field_metadata::is_foreign_key ( ) const
inline
Examples
/home/runner/work/database_system/database_system/database/orm/entity.h.

Definition at line 99 of file entity.h.

References constraints_, database::orm::foreign_key, and database::orm::has_constraint().

Referenced by TEST_F(), and TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_not_null()

bool database::orm::field_metadata::is_not_null ( ) const
inline
Examples
/home/runner/work/database_system/database_system/database/orm/entity.h.

Definition at line 95 of file entity.h.

References constraints_, database::orm::has_constraint(), and database::orm::not_null.

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), and to_sql_definition().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_primary_key()

bool database::orm::field_metadata::is_primary_key ( ) const
inline
Examples
/home/runner/work/database_system/database_system/database/orm/entity.h.

Definition at line 94 of file entity.h.

References constraints_, database::orm::has_constraint(), and database::orm::primary_key.

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), and to_sql_definition().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_unique()

bool database::orm::field_metadata::is_unique ( ) const
inline
Examples
/home/runner/work/database_system/database_system/database/orm/entity.h.

Definition at line 96 of file entity.h.

References constraints_, database::orm::has_constraint(), and database::orm::unique.

Referenced by TEST_F(), TEST_F(), and to_sql_definition().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ name()

const std::string & database::orm::field_metadata::name ( ) const
inline
Examples
/home/runner/work/database_system/database_system/database/orm/entity.h.

Definition at line 87 of file entity.h.

87{ return name_; }

References name_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ to_sql_definition()

std::string database::orm::field_metadata::to_sql_definition ( ) const
Examples
/home/runner/work/database_system/database_system/database/orm/entity.h.

Definition at line 39 of file entity.cpp.

40 {
41 std::ostringstream oss;
42 oss << name_ << " ";
43
44 // Map C++ types to SQL types
45 if (type_name_ == "int32_t" || type_name_ == "int") {
46 oss << "INTEGER";
47 } else if (type_name_ == "int64_t") {
48 oss << "BIGINT";
49 } else if (type_name_ == "double") {
50 oss << "DOUBLE PRECISION";
51 } else if (type_name_ == "std::string") {
52 oss << "VARCHAR(255)";
53 } else if (type_name_ == "bool") {
54 oss << "BOOLEAN";
55 } else if (type_name_.find("time_point") != std::string::npos) {
56 oss << "TIMESTAMP";
57 } else {
58 oss << "TEXT";
59 }
60
61 // Add constraints
62 if (is_primary_key()) {
63 oss << " PRIMARY KEY";
64 }
65 if (is_auto_increment()) {
66 oss << " AUTO_INCREMENT";
67 }
68 if (is_not_null() && !is_primary_key()) {
69 oss << " NOT NULL";
70 }
71 if (is_unique() && !is_primary_key()) {
72 oss << " UNIQUE";
73 }
74 if (has_default_now()) {
75 oss << " DEFAULT CURRENT_TIMESTAMP";
76 }
77
78 return oss.str();
79 }
bool is_primary_key() const
Definition entity.h:94
bool is_auto_increment() const
Definition entity.h:97
bool has_default_now() const
Definition entity.h:100

References has_default_now(), is_auto_increment(), is_not_null(), is_primary_key(), is_unique(), name_, and type_name_.

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ type_name()

const std::string & database::orm::field_metadata::type_name ( ) const
inline
Examples
/home/runner/work/database_system/database_system/database/orm/entity.h.

Definition at line 88 of file entity.h.

88{ return type_name_; }

References type_name_.

Referenced by TEST_F().

Here is the caller graph for this function:

Member Data Documentation

◆ constraints_

◆ foreign_field_

std::string database::orm::field_metadata::foreign_field_
private

◆ foreign_table_

std::string database::orm::field_metadata::foreign_table_
private

◆ index_name_

std::string database::orm::field_metadata::index_name_
private

◆ name_

std::string database::orm::field_metadata::name_
private

◆ type_name_

std::string database::orm::field_metadata::type_name_
private

The documentation for this class was generated from the following files: