LibrePCB Developers Documentation
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. More...
 
void addInternalData (const QString &key, int value)
 Add an integer value to the "internal" table. More...
 
int addLibrary (const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const QByteArray &iconPng, const QString &manufacturer)
 Add a library. More...
 
void updateLibrary (const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const QByteArray &iconPng, const QString &manufacturer)
 Update library metadata. More...
 
template<typename ElementType >
int addElement (int libId, const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated)
 Add a library element. More...
 
template<typename ElementType >
int addCategory (int libId, const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const tl::optional< Uuid > &parent)
 addElement() specialized for categories More...
 
int addDevice (int libId, const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const Uuid &component, const Uuid &package)
 addElement() specialized for devices More...
 
int addPart (int devId, const QString &mpn, const QString &manufacturer)
 Add a part to a previously added device. More...
 
int addPartAttribute (int partId, const Attribute &attribute)
 Add an attribute to a previously added part. More...
 
template<typename ElementType >
void removeElement (const FilePath &fp)
 Remove a library element. More...
 
template<typename ElementType >
void removeAllElements ()
 Remove all library elements of a specific type. More...
 
template<typename ElementType >
int addTranslation (int elementId, const QString &locale, const tl::optional< ElementName > &name, const tl::optional< QString > &description, const tl::optional< QString > &keywords)
 Add a translation for a library element. More...
 
template<typename ElementType >
void removeAllTranslations ()
 Remove all translations for a library element type. More...
 
template<typename ElementType >
int addToCategory (int elementId, const Uuid &category)
 Add a library element to a category. More...
 
int addAlternativeName (int pkgId, const ElementName &name, const SimpleString &reference)
 Add an alternative name to a previously added package. More...
 
WorkspaceLibraryDbWriteroperator= (const WorkspaceLibraryDbWriter &rhs)=delete
 
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
 

Static Public Member Functions

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

Private Member Functions

int addElement (const QString &elementsTable, int libId, const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated)
 
int addCategory (const QString &categoriesTable, int libId, const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const tl::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 tl::optional< ElementName > &name, const tl::optional< QString > &description, const tl::optional< QString > &keywords)
 
void removeAllTranslations (const QString &elementsTable)
 
int addToCategory (const QString &elementsTable, int elementId, const Uuid &category)
 
QString filePathToString (const FilePath &fp) const noexcept
 

Static Private Member Functions

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]

int addElement ( int  libId,
const FilePath fp,
const Uuid uuid,
const Version version,
bool  deprecated 
)
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.
Returns
ID of the added element.
+ Here is the caller graph for this function:

◆ addCategory() [1/2]

int addCategory ( int  libId,
const FilePath fp,
const Uuid uuid,
const Version version,
bool  deprecated,
const tl::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 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.
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]

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 caller graph for this function:

◆ removeAllElements() [1/2]

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 caller graph for this function:

◆ addTranslation() [1/2]

int addTranslation ( int  elementId,
const QString &  locale,
const tl::optional< ElementName > &  name,
const tl::optional< QString > &  description,
const tl::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 caller graph for this function:

◆ removeAllTranslations() [1/2]

void removeAllTranslations ( )
inline

Remove all translations for a library element type.

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

◆ addToCategory() [1/2]

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:

◆ 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]

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).
+ Here is the caller graph for this function:

◆ getCategoryTable() [1/5]

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).
+ Here is the caller graph for this function:

◆ operator=()

WorkspaceLibraryDbWriter& operator= ( const WorkspaceLibraryDbWriter rhs)
delete
+ Here is the caller graph for this function:

◆ addElement() [2/2]

int addElement ( const QString &  elementsTable,
int  libId,
const FilePath fp,
const Uuid uuid,
const Version version,
bool  deprecated 
)
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 tl::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 tl::optional< ElementName > &  name,
const tl::optional< QString > &  description,
const tl::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:

◆ filePathToString()

QString filePathToString ( const FilePath fp) const
privatenoexcept
+ 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]

QString getElementTable ( )
noexcept

◆ getElementTable() [3/8]

QString getElementTable ( )
noexcept

◆ getElementTable() [4/8]

QString getElementTable ( )
noexcept

◆ getElementTable() [5/8]

QString getElementTable ( )
noexcept

◆ getElementTable() [6/8]

QString getElementTable ( )
noexcept

◆ getElementTable() [7/8]

QString getElementTable ( )
noexcept

◆ getElementTable() [8/8]

QString getElementTable ( )
noexcept

◆ getCategoryTable() [2/5]

QString getCategoryTable ( )
noexcept

◆ getCategoryTable() [3/5]

QString getCategoryTable ( )
noexcept

◆ getCategoryTable() [4/5]

QString getCategoryTable ( )
noexcept

◆ getCategoryTable() [5/5]

QString getCategoryTable ( )
noexcept

Member Data Documentation

◆ mLibrariesRoot

FilePath mLibrariesRoot
private

◆ mDb

SQLiteDatabase& mDb
private

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