| | 24 | {{{ |
| | 25 | BEGIN; |
| | 26 | |
| | 27 | INSERT INTO components (name, brand, price, img_url, type) |
| | 28 | VALUES ($name, $brand, $price, $imgUrl, $type) |
| | 29 | RETURNING id AS new_component_id |
| | 30 | |
| | 31 | -- if type == 'cpu' |
| | 32 | INSERT INTO cpu (component_id, socket, cores, threads, base_clock, boost_clock, tdp) |
| | 33 | VALUES ($new_component_id, $socket, $cores, $threads, $base_clock, $boost_clock, $tdp); |
| | 34 | |
| | 35 | INSERT INTO cooler_cpu_sockets (cooler_id, socket) |
| | 36 | VALUES ($new_component_id, $socket); |
| | 37 | |
| | 38 | -- if type == 'gpu' |
| | 39 | INSERT INTO gpu (component_id, vram, tdp, base_clock, boost_clock, chipset, length) |
| | 40 | VALUES ($new_component_id, $vram, $tdp, $base_clock, $boost_clock, $chipset, $length); |
| | 41 | |
| | 42 | -- if type == 'memory' |
| | 43 | INSERT INTO memory (component_id, type, speed, capacity, modules) |
| | 44 | VALUES ($new_component_id, $memory_type, $speed, $capacity, $modules); |
| | 45 | |
| | 46 | -- if type == 'storage' |
| | 47 | INSERT INTO storage (component_id, type, capacity, form_factor) |
| | 48 | VALUES ($new_component_id, $storage_type, $capacity, $form_factor); |
| | 49 | |
| | 50 | -- if type == 'power_supply' |
| | 51 | INSERT INTO power_supply (component_id, type, wattage, form_factor) |
| | 52 | VALUES ($new_component_id, $psu_type, $wattage, $form_factor); |
| | 53 | |
| | 54 | -- if type == 'motherboard' |
| | 55 | INSERT INTO motherboard (component_id, socket, chipset, form_factor, ram_type, num_ram_slots, max_ram_capacity, pci_express_slots) |
| | 56 | VALUES ($new_component_id, $socket, $chipset, $form_factor, $ram_type, $num_ram_slots, $max_ram_capacity, $pci_express_slots); |
| | 57 | |
| | 58 | -- if type == 'case' |
| | 59 | INSERT INTO pc_case (component_id, cooler_max_height, gpu_max_length) |
| | 60 | VALUES ($new_component_id, $cooler_max_height, $gpu_max_length); |
| | 61 | |
| | 62 | INSERT INTO case_storage_form_factors (case_id, form_factor, num_slots) |
| | 63 | VALUES ($new_component_id, $sf_form_factor, $sf_num_slots); |
| | 64 | |
| | 65 | INSERT INTO case_ps_form_factors (case_id, form_factor) |
| | 66 | VALUES ($new_component_id, $pf_form_factor); |
| | 67 | |
| | 68 | INSERT INTO case_mobo_form_factors (case_id, form_factor) |
| | 69 | VALUES ($new_component_id, $mf_form_factor); |
| | 70 | |
| | 71 | -- if type == 'cooler' |
| | 72 | INSERT INTO cooler (component_id, type, height, max_tdp_supported) |
| | 73 | VALUES ($new_component_id, $cooler_type, $height, $max_tdp_supported); |
| | 74 | |
| | 75 | -- if type == 'memory_card' |
| | 76 | INSERT INTO memory_card (component_id, num_slots, interface) |
| | 77 | VALUES ($new_component_id, $num_slots, $interface); |
| | 78 | |
| | 79 | -- if type == 'optical_drive' |
| | 80 | INSERT INTO optical_drive (component_id, form_factor, type, interface, write_speed, read_speed) |
| | 81 | VALUES ($new_component_id, $form_factor, $optical_type, $interface, $write_speed, $read_speed); |
| | 82 | |
| | 83 | -- if type == 'sound_card' |
| | 84 | INSERT INTO sound_card (component_id, sample_rate, bit_depth, chipset, interface, channel) |
| | 85 | VALUES ($new_component_id, $sample_rate, $bit_depth, $chipset, $interface, $channel); |
| | 86 | |
| | 87 | -- if$type == 'cables' |
| | 88 | INSERT INTO cables (component_id, length_cm, type) |
| | 89 | VALUES ($new_component_id, $length_cm, $cable_type); |
| | 90 | |
| | 91 | -- if type == 'network_adapter' |
| | 92 | INSERT INTO network_adapter (component_id, wifi_version, interface, num_antennas) |
| | 93 | VALUES ($new_component_id, $wifi_version, $interface, $num_antennas); |
| | 94 | |
| | 95 | -- if type == 'network_card' |
| | 96 | INSERT INTO network_card (component_id, num_ports, speed, interface) |
| | 97 | VALUES ($new_component_id, $num_ports, $speed, $interface); |
| | 98 | |
| | 99 | COMMIT; |
| | 100 | }}} |
| | 101 | |