Using InvenTree to store KiCad Data #4133
Replies: 16 comments 71 replies
-
What about adding this as a plugin functionality instead of directly integrating this into inventree core? |
Beta Was this translation helpful? Give feedback.
-
Ok, it seems very straightforward to get running. The problem is more how you implement permissions, users, ... - maybe we start with only one supported DB and then expand? I think we might need to write a backend to handle user management. |
Beta Was this translation helpful? Give feedback.
-
F-A-N-T-A-S-T-I-C!! All KiCad team users have been waiting for it impatiently (eg. me first!) and it is finally coming! Also worth noting the new |
Beta Was this translation helpful? Give feedback.
-
Hi, not currently a user of InvenTree but would instantly start if KiCad integration was added! :) I am an EE looking for an inventory management system for our local MakerSpace. Based on InvenTree's electronics & sales focus I suspect it would not be ideal for a 'space that includes sewing, woodworking, metalworking, and other non-technical crafts. If external barcode support was an option, it could be easier to get people on board for the sales angle, but I don't see that anywhere. |
Beta Was this translation helpful? Give feedback.
-
I've just started to evaluate InvenTree & now have around 600 parts imported from PartKeepr. I'm favourably impressed so far - creating parts using the sister project, KinTree, complete with parameters is particularly useful. |
Beta Was this translation helpful? Give feedback.
-
As a read-only user - is the risk of bad things happening really very high? You could mirror the database and operate on a copy. I used something similar in PartKeepr _ accessing the mySQL database directly as a read-only user and had no problems.
… On 24 Feb 2023, at 16:52, Matthias Mair ***@***.***> wrote:
@Gasman2014 <https://github.com/Gasman2014> directly connecting to the database has serious security and operations implications, I strongly recommend against it.
—
Reply to this email directly, view it on GitHub <#4133 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ACADFOIBDGE4RGNHIK4M23LWZDRLVANCNFSM6AAAAAATOCJ6NM>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
-
That would also be my expectation. The kicad database functionality is simply a mechanism to link to an existing database via an ODBC connection. The fields accessible within kicad are exposed via a .json file which defines the connection and the field mapping. This is strictly one way read only. The addition of a symbol and footprint field (these are paths to existing files and not footprint or symbol descriptors themselves) would serve to complete the structures necessary to place a complete component.
Now, at present, it is helpful to subdivide the data into tables by class of part so that you don’t just have a ragbag of hundreds of resistors, capacitors and other components lumped together but that is a different issue.
… On 24 Feb 2023, at 21:33, Matthias Mair ***@***.***> wrote:
Maybe something changed since the testing releases for 7.0 but it populated my test-parts after I just added the parts table via the new database connection file.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
-
Can’t you use an SQL ‘View’ to bring the necessary data together in a single entity? I’m not any sort of SQL expert but I thought Views could accomplish something like this https://www.sqlshack.com/sql-view-a-complete-introduction-and-walk-through/ |
Beta Was this translation helpful? Give feedback.
-
Proof of concept.
Hacky example with a ‘View’ into a minimal ‘capacitor’ selection - Capacitors_MLCC.
You can define a .kicad_dbl to use this table to present this data within the KiCad schematic.
The only fundamental thing lacking is the ‘symbol' and ‘footprint' links.
Whilst I am sure that someone with better sql skills than myself could pick these and the other parameters from key:value pairs in the part.partparameters table but it would be much simpler to include them in part.part.
**1. Set up a ‘view’ in Inventree**
```sql
USE inventree;
CREATE VIEW Capacitors_MLCC
AS
SELECT
part_part.part_id AS part_id,
part_part.description AS Description,
part_partparameter.data AS Capacitance
FROM part_part
JOIN part_partparameter
ON part_partparameter.part_id = part_part.id
WHERE category_id = 821 AND template_id = 52
```
**2. Demonstrate that the parameters are available from the database**
```sql
SHOW * FROM Capacitors_MLCC
```
```
part_id. Description Capacitance
3324 CAP CER 0.47UF 200V X7R 1210 0.47 µF
3325 CAP CER 20PF 50V C0G/NP0 0603. 20 pF
3330 CAP CER 10PF 50V C0G/NP0 0603 10 pF
3331 CAP CER 10UF 16V X5R 0805 10 µF
3335 CAP CER 0.1UF 16V X7R 0805 0.1 µF
```
**3. Setup a kicad_dbl file with links to the database and using the ‘capacitors_mlcc' table**
This is my test.kicad_dbl file. Obviously, to be more useful, more parameters e.g. voltage, dielectric type, tolerance, package size etc need to be added. Extracting this info from the key:value pairs in ```part_partparameter``` probably needs a pivot table.
```json
{
"meta": {
"version": 0,
"filename": "demo.kicad_dbl"
},
"name": "PartKeepr Database",
"description": "An demo database from Inventree",
"source": {
"type": "odbc",
"dsn": "Demo",
"username": "******",
"password": "******",
"timeout_seconds": 20
},
"libraries": [
{
"name": "Capacitors",
"table": "capacitors_mlcc",
"key": "part_id",
"symbols": "Symbols",
"footprints": "Footprints",
"fields": [
{
"column": "Description",
"name": "ki_description",
"visible_on_add": false,
"visible_in_chooser": true
},
{
"column": "Capacitance",
"name": "Capacitance",
"visible_on_add": false,
"visible_in_chooser": false
}
]
}
]
}
```
**4. View the components from within KiCad 7**
<img width="1334" alt="Screenshot 2023-02-26 at 13 24 27" src="https://user-images.githubusercontent.com/8401593/221415155-829eddee-8921-4b1b-8ad0-0f216fed39f7.png">
As you can see, the capacitance is now accessible as a parameter from the ‘view’ table.
Now, as I mentioned, the feature missing is a suitable place to store the symbol and footprint paths. This need only be two additional VARCHAR fields (if you are happy with paths <=255 characters) in ```part_part```. This info probably could be included as key:value pairs in the parameters but it would be simpler in the ```part_part``` table.
So, a read-only ‘View’ directly into the database with parameters available IS possible. I believe the risk of database corruption is absolutely minimal.
… On 24 Feb 2023, at 22:00, Francois ***@***.***> wrote:
See my comments above:
#4133 (reply in thread) <#4133 (reply in thread)>
#4133 (reply in thread) <#4133 (reply in thread)>
As I said library to database table is one-to-one matching.
InvenTree data is spread among many database tables.
KiCad .kicad_dbl does not allow to map different fields to different tables at the moment, or not that I'm aware of.
So if you want to load a database library in KiCad V7, you need a ALL the data (fields and properties) for all parts in the library to be contained in a single database table.
—
Reply to this email directly, view it on GitHub <#4133 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ACADFOM7EIPAV4SSXGLELN3WZEVQHANCNFSM6AAAAAATOCJ6NM>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
-
Just to extend my example (and to leave it here for anyone who is interested in using the 'View' approach), here is a way to generate a more comprehensive SINGLE table that pulls in parameters from the
SELECT * FROM inventree.capacitors_mlcc; produces
The table is generated by using the following SQL setup. Rinse and repeat/adjust for any other components you chose - you can set up separate tables for THT or SMD components etc. by appropriate choice of CREATE VIEW Capacitors_MLCC
AS
SELECT
part_id AS part_id,
part_part.description AS Description,
MAX(
CASE part_partparameter.template_id
WHEN '52' THEN data ELSE NULL
END
) AS 'Capacitance',
MAX(
CASE part_partparameter.template_id
WHEN '51' THEN data ELSE NULL
END
) AS 'Tolerance',
MAX(
CASE part_partparameter.template_id
WHEN '49' THEN data ELSE NULL
END
) AS 'Dielectric',
MAX(
CASE part_partparameter.template_id
WHEN '36' THEN data ELSE NULL
END
) AS 'Case',
MAX(
case part_partparameter.template_id
WHEN '44' THEN data ELSE NULL
END
) AS 'Voltage'
FROM part_part
LEFT JOIN part_partparameter
ON part_partparameter.part_id = part_part.id
WHERE category_id = 821
GROUP BY part_part.id |
Beta Was this translation helpful? Give feedback.
-
Checking in here, after losing track of the discussion for a bit. @Gasman2014 an interesting approach, how would the kicad .exe gain access to the "view" - does it need to be on the same local machine, or do we expose the sql server to a common network? |
Beta Was this translation helpful? Give feedback.
-
I've been following the discussions here as I am also very interested in interfacing KiCad with InvenTree. I recently found a post on the KiCad forums A Database case study that uses SQLite3ODBC to access parts imported from existing CSV files into an SQLite3 database. I was inspired by this approach to create a generic "middleware" (appologies in advance for using that term) which uses SQLite3ODBC and SQLite3 virtual tables to pull data directly from the existing InvenTree API. A proof of concept with instructions is available here: https://github.com/clj/kom There is still a bunch of work to be done for this to become a usable solution, but it currently works for simple parts (e.g., passives that all use the same symbol) and the performance is (very unscientifically) pretty decent, hitting an Invetree instance hosted on a Digital Ocean VPS. I think there are some benefits to this approach, for example:
A significant downside is that it does require a bunch of configuration steps, including running SQL statements using SQLite. This could possibly be abstracted away by a GUI if somebody had the inclination to write some code to do that. There is still a bunch of work to do:
|
Beta Was this translation helpful? Give feedback.
-
The “views” approach is what I’ve been using but my implementation didn’t seem to be very popular due to a perceived security risk and the necessary individual configuration. It does require a fair bit of customised setup but, once done, is fairly solid. I’ve also done this with a series of views into a MySQL PartKeepr database which pulls in a number of parameters including stock availability. Views allow you to construct a new, conditionally determined table on the remote database with data from a number of related tables and built on the fly from an sql query.FWIW this also seems to be the approach used by the Altium Library project.issus/altium-library: Open source Altium Database Library with over 165,000 high quality components and full 3d models.github.comThis is why I think a views based approach would be useful as the work can be done on the server and the user can have permissions set just to query the views. The present KiCad approach needs those stored locally - so the Database Library would have to have fields to record the paths. I think there was some talk about allowing KiCad to access a symbol/footprint definition held as a blob on the database itself. Similarly how to access the 3d models which are also references to local files but could pull in a remotely held .step file. These are limitations of the current database implementation. On 9 May 2023, at 10:29, Lukas ***@***.***> wrote:
But what is with this sql views approach? Wasn't that using the inventree psql/MySQL db on a remote server so remote should be supported?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hey, so I have been wondering about parts vs manufacturer parts for a while. Currently in the KiCad/InvenTree integration I'm just pulling parts and part IPNs. Those parts though, have potentially a number of manufacturer parts. Since I'm making an assembled board (using JLCPCB) I need the LCSC part numbers to be able to create a position and bom file for the assembly. And ideally, because I'm using KiBot this is all going to be embedded in the project or at least somehow in the repository so that all the relevant files can be built using the GitHub Actions automation that I have set up. I'm wondering how the workflow for that looks and whether the integration is doing the right thing here. Manufacturer parts can probably be pulled from the API and exposed the same way as metadata or parameters, but is that the right thing to do? I especially don't see how this works if there are more than one manufacturer part, then there is no way of selecting which manufacturer part that should be used. Or, should there be a separate step, using e.g. a KiCad PCBNew plugin that assigns manufacturer parts? Or something else? Has anyone had a thought about how this should work? |
Beta Was this translation helpful? Give feedback.
-
For information: There also are parallel actions on KiCAD side to integrate REST API access into KiCAD: |
Beta Was this translation helpful? Give feedback.
-
Hey everyone, a quick update! The HTTP library support has now been accepted and merged into the KiCad nightly builds! Very exciting, and congratulations to @afkiwers for his efforts to get this across the line. There is now also an InvenTree plugin which Andre and I have been working on over the last few days. Check out the documentation there - it is very easy to use and provides seamless integration of InvenTree data into your KiCad library. This has been a very long time coming, and I am super excited that it is finally here! Please do check out the plugin, and raise any issues over there. Note that you'll need to be running KiCad nightly builds until the next release on their end :) |
Beta Was this translation helpful? Give feedback.
-
As discussed in the recent KiCad development blog, version 7 of KiCad will support external databases for component libraries.
Given that (for a lot of people) InvenTree is already integrated with their EE workflow (BOMs etc), perhaps there is a way of storing raw part data in InvenTree itself, for a very tight integration between these two pieces of OSS.
Ref: https://docs.kicad.org/master/en/eeschema/eeschema.html#database_libraries
Beta Was this translation helpful? Give feedback.
All reactions