Skip to content

Commit 1d8a836

Browse files
Merge pull request pradanvirudhunagar#17 from Churchill427/main
SQL:insertion_in_forms
2 parents 1c5fac0 + c55787b commit 1d8a836

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

sql_queries/insertion_in_forms.sql

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

0 commit comments

Comments
 (0)