64 [&]() -> nlohmann::json
67 return m_librariesConfig;
69 [&](
const nlohmann::json& aObj )
72 m_librariesConfig = aObj;
74 if( !aObj.is_array() )
77 for( const nlohmann::json& entry : aObj )
79 if( entry.empty() || !entry.is_object() )
82 DATABASE_LIB_TABLE table;
84 table.name = entry[
"name"].get<std::string>();
85 table.table = entry[
"table"].get<std::string>();
86 table.key_col = entry[
"key"].get<std::string>();
87 table.symbols_col = entry[
"symbols"].get<std::string>();
88 table.footprints_col = entry[
"footprints"].get<std::string>();
89 table.pins_col = fetchOrDefault<std::string>( entry,
"pins" );
93 std::erase( table.name,
'/' );
95 if( entry.contains(
"properties" ) && entry[
"properties"].is_object() )
97 const nlohmann::json& propJson = entry[
"properties"];
99 table.properties.description =
100 fetchOrDefault<std::string>( propJson,
"description" );
102 table.properties.footprint_filters =
103 fetchOrDefault<std::string>( propJson,
"footprint_filters" );
105 table.properties.keywords =
106 fetchOrDefault<std::string>( propJson,
"keywords" );
108 table.properties.exclude_from_bom =
109 fetchOrDefault<std::string>( propJson,
"exclude_from_bom" );
111 table.properties.exclude_from_board =
112 fetchOrDefault<std::string>( propJson,
"exclude_from_board" );
114 table.properties.exclude_from_sim =
115 fetchOrDefault<std::string>( propJson,
"exclude_from_sim" );
118 if( entry.contains(
"fields" ) && entry[
"fields"].is_array() )
120 for( const nlohmann::json& fieldJson : entry[
"fields"] )
122 if( fieldJson.empty() || !fieldJson.is_object() )
125 table.fields.emplace_back( DATABASE_FIELD_MAPPING(
126 fetchOrDefault<std::string>( fieldJson,
"column" ),
127 fetchOrDefault<std::string>( fieldJson,
"name" ),
128 fetchOrDefault<bool>( fieldJson,
"visible_on_add" ),
129 fetchOrDefault<bool>( fieldJson,
"visible_in_chooser" ),
130 fetchOrDefault<bool>( fieldJson,
"show_name" ),
131 fetchOrDefault<bool>( fieldJson,
"inherit_properties" ) ) );
135 m_Tables.emplace_back( std::move( table ) );
140 m_params.emplace_back(
new PARAM<int>(
"cache.max_size", &m_Cache.max_size, 256 ) );
142 m_params.emplace_back(
new PARAM<int>(
"cache.max_age", &m_Cache.max_age, 60 ) );
144 m_params.emplace_back(
new PARAM<bool>(
"globally_unique_keys", &m_GloballyUniqueKeys,
false ) );
146 registerMigration( 0, 1,
154 if( !Contains(
"libraries" ) || !At(
"libraries" ).is_array() )
157 for( nlohmann::json&
library : At(
"libraries" ) )
159 if( !
library.contains(
"fields" ) )
162 for(
const nlohmann::json& field :
library[
"fields"] )
164 if( !field.contains(
"name" ) || !field.contains(
"column" ) )
167 std::string
name = field[
"name"].get<std::string>();
168 std::string col = field[
"column"].get<std::string>();
170 if(
name ==
"ki_description" )
171 library[
"properties"][
"description"] = col;
172 else if(
name ==
"ki_fp_filters" )
173 library[
"properties"][
"footprint_filters"] = col;