Skip to content

Commit 473eb2d

Browse files
committed
sql_insertion_farm_pond
1 parent e48dc22 commit 473eb2d

File tree

1 file changed

+76
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)