remove pincount, just use package

This commit is contained in:
King Kévin 2023-01-29 10:09:42 +01:00
parent 2ef85a2008
commit 7dc2c6753e
5 changed files with 9 additions and 23 deletions

View File

@ -1,9 +1,6 @@
-- manufacturers
INSERT INTO manufacturer (name, homepage, search) VALUES ("Espressif", "https://www.espressif.com/", "https://products.espressif.com/#/product-selector");
-- packages
INSERT INTO package (name) VALUES ("module");
-- distributors
INSERT INTO distributor (name, homepage, product_page) VALUES ("LCSC", "https://www.lcsc.com/", "https://www.lcsc.com/product-detail/%s.html");
INSERT INTO distributor (name, homepage, product_page) VALUES ("JLCPCB", "https://jlcpcb.com/", "https://jlcpcb.com/partdetail/part/%s");
@ -14,7 +11,7 @@ INSERT INTO distributor (name, homepage, product_page) VALUES ("Octopart", "http
INSERT INTO distributor (name, homepage, product_page) VALUES ("AliExpress", "https://www.aliexpress.com/", "https://aliexpress.com/item/%s.html");
-- parts
INSERT INTO part (name, description, manufacturer, datasheet, package, pincount, page) VALUES ("ESP32-S3-WROOM-1", "ESP32-S3 module, PCB antenna", (SELECT id FROM manufacturer WHERE name = "Espressif"), "https://www.espressif.com/sites/default/files/documentation/esp32-s3-wroom-1_wroom-1u_datasheet_en.pdf", (SELECT id FROM package WHERE name = "module"), 49, "https://www.espressif.com/en/module/esp32-s3-wroom-1-en");
INSERT INTO part (name, description, manufacturer, datasheet, package, page) VALUES ("ESP32-S3-WROOM-1", "ESP32-S3 module, PCB antenna", (SELECT id FROM manufacturer WHERE name = "Espressif"), "https://www.espressif.com/sites/default/files/documentation/esp32-s3-wroom-1_wroom-1u_datasheet_en.pdf", "module-49", "https://www.espressif.com/en/module/esp32-s3-wroom-1-en");
INSERT INTO part (name, description) VALUES ("ESP32-S3-WROOM-1-N4", "ESP32-S3 module, PCB antenna, 4MB flash");
UPDATE part SET family=(SELECT id FROM part WHERE name = "ESP32-S3-WROOM-1") WHERE name = "ESP32-S3-WROOM-1-N4";

View File

@ -25,7 +25,7 @@
<div class="name">description:</div><div class="justify"><input class="full" type="text" id="part_description"></div>
<div>details:</div>
<div class="justify"><textarea class="full" id="part_details" rows="4"></textarea></div>
<div>package: <input type="text" id="part_package" size="4">-<input type="text" id="part_pincount" size="2"></div>
<div class="name">package:</div><div class="justify"><input class="full" type="text" id="part_package"></div>
<div class="name">manufacturer:</div><div class="justify"><input class="full" type="text" id="part_manufacturer"></div>
<div class="name">mpn:</div><div class="justify"><input class="full" type="text" id="part_mpn"></div>
<div class="name">family:</div><div class="justify"><input class="full" type="text" id="part_family"></div>

View File

@ -9,7 +9,7 @@ var last_search = null;
// the collection of parts
var parts = null;
// part field to populate
const fields = ["name", "description", "details", "package", "pincount", "manufacturer", "mpn", "family", "datasheet", "page", "location", "stock"];
const fields = ["name", "description", "details", "package", "manufacturer", "mpn", "family", "datasheet", "page", "location", "stock"];
// URLs to set
const urls = ["page","datasheet"];

View File

@ -20,14 +20,6 @@ CREATE TABLE IF NOT EXISTS distributor (
product_page TEXT -- URL to product page (%s is replace by sku)
);
-- part package
CREATE TABLE IF NOT EXISTS package (
id INTEGER AUTO_INCREMENT PRIMARY KEY, -- index
name TEXT NOT NULL UNIQUE,
family INTEGER, -- if this package is part of a more general package family
FOREIGN KEY (family) REFERENCES package (id)
);
-- the part itself
CREATE TABLE IF NOT EXISTS part (
id INTEGER AUTO_INCREMENT PRIMARY KEY, -- index
@ -38,12 +30,10 @@ CREATE TABLE IF NOT EXISTS part (
mpn TEXT,
family INTEGER, -- if this part is part of a part family
datasheet TEXT, -- URL to datasheet
package INTEGER,
pincount INTEGER,
package TEXT,
page TEXT, -- URL to product page
FOREIGN KEY (manufacturer) REFERENCES manufacturer (id),
FOREIGN KEY (family) REFERENCES part (id),
FOREIGN KEY (package) REFERENCES package (id)
FOREIGN KEY (family) REFERENCES part (id)
);
-- a project (as part) can be an assembly of other parts

View File

@ -79,7 +79,7 @@ end
def get_part_by_id(id)
return nil unless id
statement = @db.prepare("SELECT part.id, part.name, part.description, part.details, part.datasheet, manufacturer.name AS manufacturer, part.mpn AS mpn, package.name AS package, part.pincount AS pincount, part.page AS page, part.family AS parent, p2.name AS family FROM part LEFT JOIN package ON package.id = part.package LEFT JOIN manufacturer ON manufacturer.id = part.manufacturer LEFT JOIN part AS p2 ON p2.id = part.family WHERE part.id = ?")
statement = @db.prepare("SELECT part.id, part.name, part.description, part.details, part.datasheet, manufacturer.name AS manufacturer, part.mpn AS mpn, package.name AS package, part.page AS page, part.family AS parent, p2.name AS family FROM part LEFT JOIN package ON package.id = part.package LEFT JOIN manufacturer ON manufacturer.id = part.manufacturer LEFT JOIN part AS p2 ON p2.id = part.family WHERE part.id = ?")
part = statement.execute(id).to_a[0]
return nil unless part
parent = get_part_by_id(part["parent"])
@ -259,17 +259,16 @@ def add_part(part)
family = get_part_by_id(family[0]["id"])
end
# update fields
fields_txt = ["name", "description", "details", "mpn", "pincount", "datasheet", "page"];
fields_txt = ["name", "description", "details", "mpn", "package", "datasheet", "page"];
fields_txt.each do |field|
next unless part[field]
part[field] = nil if part[field].kind_of?(String) and 0 == part[field].length
part[field] = part[field].to_i if part[field] and "pincount" == field
next if family and family[field] == part[field]
update = @db.prepare("UPDATE part SET #{field} = ? WHERE id = ?")
update.execute(part[field], part["id"])
end
# update manufacturer and package
field_ref = ["manufacturer", "package"]
field_ref = ["manufacturer"]
field_ref.each do |field|
part[field] = nil if part[field] and 0 == part[field].length
next if family and family[field] == part[field]
@ -383,7 +382,7 @@ get '/import/lcsc/:lcsc' do
part["description"] = result["productDescEn"]
part["details"] = result["productIntroEn"]
part["manufacturer"] = result["brandNameEn"]
part["package"] = result["encapStandard"] # also includes pin count
part["package"] = result["encapStandard"]
part["distributors"] = {"LCSC" => result["productCode"]}
part["attachments"] = result["productImages"]
part["datasheet"] = result["pdfUrl"]