Skip to content

Commit e80d0f5

Browse files
committed
sql_insertion_forms_plantation_details
1 parent eab1a5f commit e80d0f5

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const mysql = require('mysql2/promise');
2+
3+
async function insertAllFormData() {
4+
const connection = await mysql.createConnection({
5+
host: 'localhost',
6+
user: 'root',
7+
database: 'your_db'
8+
});
9+
10+
try {
11+
await connection.beginTransaction();
12+
13+
// 1. Insert into forms
14+
const [formResult] = await connection.execute(
15+
`INSERT INTO forms (
16+
farmer_name, age, mobile, district, block, panchayat, hamlet,
17+
id_type, id_number, gender, spouse, type_of_households, h_members,
18+
hh_occupation, special_catog, caste, house_owner, type_of_house,
19+
drinking_water, potability, domestic_water, toilet_avail, toilet_cond,
20+
household_education, user_id, created_at, lat, lon, status, form_type
21+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
22+
[2, 'FARMER_NAME', 'AGE', 9876543210, 'DISTRICT', 'BLOCK', 'PANCHAYAT', 'HAMLET',
23+
'ID_TYPE', 'ID_NUMBER', 'GENDER', 'SPOUSE', 'HOUSEHOLD_TYPE', 5,
24+
'OCCUPATION', 'SPECIAL_CAT', 'CASTE', 'OWNER', 'HOUSE_TYPE',
25+
'DRINK_WATER', 'POTABILITY', 'DOMESTIC_WATER', 'TOILET_AVAIL', 'TOILET_COND',
26+
'EDUCATION', 1, '2025-04-16', 'LAT', 'LON', 'MCODE', 1]
27+
);
28+
29+
const formId = formResult.insertId;
30+
31+
// 2. Insert into bank_details
32+
await connection.execute(
33+
`INSERT INTO bank_details (
34+
form_id, account_holder_name, account_number, bank_name,
35+
branch, ifsc_code, farmer_ack
36+
) VALUES (?, ?, ?, ?, ?, ?, ?)`,
37+
[formId, 'ACCOUNT_HOLDER', 123456789012, 'BANK_NAME',
38+
'BRANCH_NAME', 'IFSC00001', 'ACKNOWLEDGED']
39+
);
40+
41+
// 3. Insert into files
42+
await connection.execute(
43+
`INSERT INTO files (
44+
form_id, identity, geotag, patta, fmb, photo, passbook
45+
) VALUES (?, ?, ?, ?, ?, ?, ?)`,
46+
[formId, 'IDENTITY_DOC', 'GEOTAG_URL', 'PATTA_DOC', 'FMB_DOC', 'PHOTO_URL', 'PASSBOOK_DOC']
47+
);
48+
49+
// 4. Insert into plantation_details
50+
await connection.execute(
51+
`INSERT INTO plantation_details (
52+
form_id, ownership, well_irrigation, area_irrigated, irrigated_lands,
53+
patta, total_area, taluk, firka, revenue, crop_season, livestocks,
54+
sf_number, soil_type, land_to_benefit, date_of_ins, type_of_work,
55+
area_benefited_by_proposal, any_other_works, p_contribution, f_contribution,
56+
total_est, field_insp, site_app, date_of_app, plantaions, nos, price,
57+
other_exp, tot_nos, tot_price, verified_by
58+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
59+
[formId, 'OWNERSHIP', 'WELL_IRR', 'AREA_IRR', 'IRRIG_LAND',
60+
'PATTA', 'TOT_AREA', 'TALUK', 'FIRKA', 'REVENUE', 'CROP_SEASON', 'LIVESTOCKS',
61+
'SF_NO', 'SOIL', 'LAND_BENEFIT', 'DATE_INS', 'WORK_TYPE',
62+
'AREA_BENEFITED', 'OTHER_WORKS', 'P_CONTRI', 'F_CONTRI',
63+
'EST_TOTAL', 'INSP', 'SITE_APP', 'APP_DATE', 'PLANTATIONS', 100, 50000,
64+
10000, 100, 5000000, 'VERIFIER']
65+
);
66+
67+
await connection.commit();
68+
console.log("All data inserted successfully with form_id:", formId);
69+
} catch (err) {
70+
await connection.rollback();
71+
console.error("Transaction failed:", err);
72+
} finally {
73+
await connection.end();
74+
}
75+
}

0 commit comments

Comments
 (0)