LibrePCB Developers Documentation
Loading...
Searching...
No Matches
WorkspaceLibraryDbWriter Class Referencefinal

Database write functions for librepcb::WorkspaceLibraryDb. More...

#include <workspacelibrarydbwriter.h>

+ Collaboration diagram for WorkspaceLibraryDbWriter:

Public Member Functions

 WorkspaceLibraryDbWriter ()=delete
 
 WorkspaceLibraryDbWriter (const WorkspaceLibraryDbWriter &other)=delete
 
 WorkspaceLibraryDbWriter (const FilePath &librariesRoot, SQLiteDatabase &db)
 
 ~WorkspaceLibraryDbWriter () noexcept
 
void createAllTables ()
 Create all tables to initialize the database.
 
void addInternalData (const QString &key, int value)
 Add an integer value to the "internal" table.
 
int addLibrary (const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const QByteArray &iconPng, const QString &manufacturer)
 Add a library.
 
void updateLibrary (const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const QByteArray &iconPng, const QString &manufacturer)
 Update library metadata.
 
template<typename ElementType >
int addElement (int libId, const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const QString &generatedBy)
 Add a library element.
 
template<typename ElementType >
int addCategory (int libId, const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const std::optional< Uuid > &parent)
 addElement() specialized for categories
 
int addDevice (int libId, const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const QString &generatedBy, const Uuid &component, const Uuid &package)
 addElement() specialized for devices
 
int addPart (int devId, const QString &mpn, const QString &manufacturer)
 Add a part to a previously added device.
 
int addPartAttribute (int partId, const Attribute &attribute)
 Add an attribute to a previously added part.
 
template<typename ElementType >
void removeElement (const FilePath &fp)
 Remove a library element.
 
template<typename ElementType >
void removeAllElements ()
 Remove all library elements of a specific type.
 
template<typename ElementType >
int addTranslation (int elementId, const QString &locale, const std::optional< ElementName > &name, const std::optional< QString > &description, const std::optional< QString > &keywords)
 Add a translation for a library element.
 
template<typename ElementType >
void removeAllTranslations ()
 Remove all translations for a library element type.
 
template<typename ElementType >
int addToCategory (int elementId, const Uuid &category)
 Add a library element to a category.
 
template<typename ElementType >
int addResource (int elementId, const QString &name, const QString &mediaType, const QUrl &url)
 Add a resource for a library element.
 
int addAlternativeName (int pkgId, const ElementName &name, const SimpleString &reference)
 Add an alternative name to a previously added package.
 
WorkspaceLibraryDbWriteroperator= (const WorkspaceLibraryDbWriter &rhs)=delete
 

Static Public Member Functions

template<typename ElementType >
static QString getElementTable () noexcept
 Get the table name of an element type.
 
template<typename ElementType >
static QString getCategoryTable () noexcept
 Get the category table name of an element type.
 
template<>
QString getElementTable () noexcept
 
template<>
QString getElementTable () noexcept
 
template<>
QString getElementTable () noexcept
 
template<>
QString getElementTable () noexcept
 
template<>
QString getElementTable () noexcept
 
template<>
QString getElementTable () noexcept
 
template<>
QString getElementTable () noexcept
 
template<>
QString getCategoryTable () noexcept
 
template<>
QString getCategoryTable () noexcept
 
template<>
QString getCategoryTable () noexcept
 
template<>
QString getCategoryTable () noexcept
 

Private Member Functions

int addElement (const QString &elementsTable, int libId, const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const QString &generatedBy)
 
int addCategory (const QString &categoriesTable, int libId, const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const std::optional< Uuid > &parent)
 
void removeElement (const QString &elementsTable, const FilePath &fp)
 
void removeAllElements (const QString &elementsTable)
 
int addTranslation (const QString &elementsTable, int elementId, const QString &locale, const std::optional< ElementName > &name, const std::optional< QString > &description, const std::optional< QString > &keywords)
 
void removeAllTranslations (const QString &elementsTable)
 
int addToCategory (const QString &elementsTable, int elementId, const Uuid &category)
 
int addResource (const QString &elementsTable, int elementId, const QString &name, const QString &mediaType, const QUrl &url)
 
QString filePathToString (const FilePath &fp) const noexcept
 

Static Private Member Functions

static QString nonEmptyOrNull (const QString &s) noexcept
 
static QString nonNull (const QString &s) noexcept
 

Private Attributes

FilePath mLibrariesRoot
 
SQLiteDatabasemDb
 

Detailed Description

Database write functions for librepcb::WorkspaceLibraryDb.

Constructor & Destructor Documentation

◆ WorkspaceLibraryDbWriter() [1/3]

◆ WorkspaceLibraryDbWriter() [2/3]

◆ WorkspaceLibraryDbWriter() [3/3]

WorkspaceLibraryDbWriter ( const FilePath librariesRoot,
SQLiteDatabase db 
)

◆ ~WorkspaceLibraryDbWriter()

~WorkspaceLibraryDbWriter ( )
noexcept

Member Function Documentation

◆ createAllTables()

void createAllTables ( )

Create all tables to initialize the database.

This has to be done only once, after creating a new database.

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

◆ addInternalData()

void addInternalData ( const QString &  key,
int  value 
)

Add an integer value to the "internal" table.

Parameters
keyThe key to add.
valueThe value to add.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addLibrary()

int addLibrary ( const FilePath fp,
const Uuid uuid,
const Version version,
bool  deprecated,
const QByteArray &  iconPng,
const QString &  manufacturer 
)

Add a library.

Parameters
fpFilepath of the library.
uuidUUID of the library.
versionVersion of the library.
deprecatedWhether the library is deprecated or not.
iconPngIcon as a PNG.
manufacturerName of the manufacturer of this library (optional).
Returns
ID of the added library.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateLibrary()

void updateLibrary ( const FilePath fp,
const Uuid uuid,
const Version version,
bool  deprecated,
const QByteArray &  iconPng,
const QString &  manufacturer 
)

Update library metadata.

Parameters
fpFilepath of the library to update.
uuidNew UUID of the library.
versionNew version of the library.
deprecatedWhether the library is deprecated or not.
iconPngNew icon as a PNG.
manufacturerName of the manufacturer of this library (optional).
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addElement() [1/2]

template<typename ElementType >
int addElement ( int  libId,
const FilePath fp,
const Uuid uuid,
const Version version,
bool  deprecated,
const QString &  generatedBy 
)
inline

Add a library element.

Template Parameters
ElementTypeType of element to add.
Parameters
libIdID of the library containing this element.
fpFilepath of the element.
uuidUUID of the element.
versionVersion of the element.
deprecatedWhether the element is deprecated or not.
generatedByThe generator name if generated or imported.
Returns
ID of the added element.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addCategory() [1/2]

template<typename ElementType >
int addCategory ( int  libId,
const FilePath fp,
const Uuid uuid,
const Version version,
bool  deprecated,
const std::optional< Uuid > &  parent 
)
inline

addElement() specialized for categories

Template Parameters
ElementTypeType of category to add.
Parameters
libIdID of the library containing this category.
fpFilepath of the category.
uuidUUID of the category.
versionVersion of the category.
deprecatedWhether the category is deprecated or not.
parentParent of the category.
Returns
ID of the added category.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addDevice()

int addDevice ( int  libId,
const FilePath fp,
const Uuid uuid,
const Version version,
bool  deprecated,
const QString &  generatedBy,
const Uuid component,
const Uuid package 
)

addElement() specialized for devices

Parameters
libIdID of the library containing this device.
fpFilepath of the device.
uuidUUID of the device.
versionVersion of the device.
deprecatedWhether the device is deprecated or not.
generatedByThe generator name if generated or imported.
componentComponent UUID of the device.
packagePackage UUID of the device.
Returns
ID of the added device.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addPart()

int addPart ( int  devId,
const QString &  mpn,
const QString &  manufacturer 
)

Add a part to a previously added device.

Parameters
devIdID of the device containing this part.
mpnManufacturer part number.
manufacturerManufacturer name.
Returns
ID of the added part.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addPartAttribute()

int addPartAttribute ( int  partId,
const Attribute attribute 
)

Add an attribute to a previously added part.

Parameters
partIdID of the part containing this attribute.
attributeAttribute to add.
Returns
ID of the added attribute.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeElement() [1/2]

template<typename ElementType >
void removeElement ( const FilePath fp)
inline

Remove a library element.

Note
This will automatically remove its translations and categories as well.
Template Parameters
ElementTypeType of element to remove.
Parameters
fpFilepath of the element to remove.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeAllElements() [1/2]

template<typename ElementType >
void removeAllElements ( )
inline

Remove all library elements of a specific type.

Note
This will automatically remove their translations and categories as well.
Template Parameters
ElementTypeType of elements to remove.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addTranslation() [1/2]

template<typename ElementType >
int addTranslation ( int  elementId,
const QString &  locale,
const std::optional< ElementName > &  name,
const std::optional< QString > &  description,
const std::optional< QString > &  keywords 
)
inline

Add a translation for a library element.

Template Parameters
ElementTypeType of element to add translations.
Parameters
elementIdID of the element to add translations.
localeLocale of the translations.
nameElement name.
descriptionEleemnt description.
keywordsElement keywords.
Returns
ID of the added translation.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeAllTranslations() [1/2]

template<typename ElementType >
void removeAllTranslations ( )
inline

Remove all translations for a library element type.

Template Parameters
ElementTypeType of element to remove translationss.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addToCategory() [1/2]

template<typename ElementType >
int addToCategory ( int  elementId,
const Uuid category 
)
inline

Add a library element to a category.

Template Parameters
ElementTypeType of element to add to the category.
Parameters
elementIdID of the element to add to the category.
categoryCategory UUID.
Returns
ID of the added category.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addResource() [1/2]

template<typename ElementType >
int addResource ( int  elementId,
const QString &  name,
const QString &  mediaType,
const QUrl &  url 
)
inline

Add a resource for a library element.

Template Parameters
ElementTypeType of element of the resource.
Parameters
elementIdID of the element of the resource.
nameResource name
mediaTypeResource media type.
urlResource URL.
Returns
ID of the added resource.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addAlternativeName()

int addAlternativeName ( int  pkgId,
const ElementName name,
const SimpleString reference 
)

Add an alternative name to a previously added package.

Parameters
pkgIdID of the package for this alternative name.
nameAlternative name (mandatory).
referenceOrigin of the alternative name (optional).
Returns
ID of the added part.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getElementTable() [1/8]

template<typename ElementType >
static QString getElementTable ( )
staticnoexcept

Get the table name of an element type.

Template Parameters
ElementTypeType of element to get the table name of.
Returns
Table name (e.g. "symbols" for librepcb::Symbol).

◆ getCategoryTable() [1/5]

template<typename ElementType >
static QString getCategoryTable ( )
staticnoexcept

Get the category table name of an element type.

Template Parameters
ElementTypeType of element to get the category table name of.
Returns
Category table name (e.g. "component_categories" for librepcb::Symbol).

◆ operator=()

WorkspaceLibraryDbWriter & operator= ( const WorkspaceLibraryDbWriter rhs)
delete

◆ addElement() [2/2]

int addElement ( const QString &  elementsTable,
int  libId,
const FilePath fp,
const Uuid uuid,
const Version version,
bool  deprecated,
const QString &  generatedBy 
)
private
+ Here is the call graph for this function:

◆ addCategory() [2/2]

int addCategory ( const QString &  categoriesTable,
int  libId,
const FilePath fp,
const Uuid uuid,
const Version version,
bool  deprecated,
const std::optional< Uuid > &  parent 
)
private
+ Here is the call graph for this function:

◆ removeElement() [2/2]

void removeElement ( const QString &  elementsTable,
const FilePath fp 
)
private
+ Here is the call graph for this function:

◆ removeAllElements() [2/2]

void removeAllElements ( const QString &  elementsTable)
private
+ Here is the call graph for this function:

◆ addTranslation() [2/2]

int addTranslation ( const QString &  elementsTable,
int  elementId,
const QString &  locale,
const std::optional< ElementName > &  name,
const std::optional< QString > &  description,
const std::optional< QString > &  keywords 
)
private
+ Here is the call graph for this function:

◆ removeAllTranslations() [2/2]

void removeAllTranslations ( const QString &  elementsTable)
private
+ Here is the call graph for this function:

◆ addToCategory() [2/2]

int addToCategory ( const QString &  elementsTable,
int  elementId,
const Uuid category 
)
private
+ Here is the call graph for this function:

◆ addResource() [2/2]

int addResource ( const QString &  elementsTable,
int  elementId,
const QString &  name,
const QString &  mediaType,
const QUrl &  url 
)
private
+ Here is the call graph for this function:

◆ filePathToString()

QString filePathToString ( const FilePath fp) const
privatenoexcept
+ Here is the caller graph for this function:

◆ nonEmptyOrNull()

QString nonEmptyOrNull ( const QString &  s)
staticprivatenoexcept
+ Here is the caller graph for this function:

◆ nonNull()

QString nonNull ( const QString &  s)
staticprivatenoexcept
+ Here is the caller graph for this function:

◆ getElementTable() [2/8]

template<>
QString getElementTable ( )
staticnoexcept

◆ getElementTable() [3/8]

template<>
QString getElementTable ( )
staticnoexcept

◆ getElementTable() [4/8]

template<>
QString getElementTable ( )
staticnoexcept

◆ getElementTable() [5/8]

template<>
QString getElementTable ( )
staticnoexcept

◆ getElementTable() [6/8]

template<>
QString getElementTable ( )
staticnoexcept

◆ getElementTable() [7/8]

template<>
QString getElementTable ( )
staticnoexcept

◆ getElementTable() [8/8]

template<>
QString getElementTable ( )
staticnoexcept

◆ getCategoryTable() [2/5]

template<>
QString getCategoryTable ( )
staticnoexcept

◆ getCategoryTable() [3/5]

template<>
QString getCategoryTable ( )
staticnoexcept

◆ getCategoryTable() [4/5]

template<>
QString getCategoryTable ( )
staticnoexcept

◆ getCategoryTable() [5/5]

template<>
QString getCategoryTable ( )
staticnoexcept

Member Data Documentation

◆ mLibrariesRoot

FilePath mLibrariesRoot
private

◆ mDb

SQLiteDatabase& mDb
private

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