Skip to content

Commit c2d75c4

Browse files
Merge pull request pradanvirudhunagar#18 from Churchill427/main
sql_insertion_plantation_details
2 parents d5c1e76 + 87e96b1 commit c2d75c4

File tree

2 files changed

+149
-0
lines changed

2 files changed

+149
-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+
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
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', '10', '20',
62+
'5', '1000', 'P_CONTRI', 'F_CONTRI', 'EST_TOTAL', 'AREA_BENEFITED',
63+
'INSP', 'SITE_APP', 'APP_DATE', 'LEN_PF', 'BRE_PF', 'DEP_PF', 'VOL_PF',
64+
'AREA_BENEFITED_PF', '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+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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, date_of_app, plantaions
57+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
58+
[formId, 'OWNERSHIP', 'WELL_IRR', 'AREA_IRR', 'IRRIG_LAND',
59+
'PATTA', 'TOT_AREA', 'TALUK', 'FIRKA', 'REVENUE', 'CROP_SEASON', 'LIVESTOCKS',
60+
'SF_NO', 'SOIL', 'LAND_BENEFIT', 'DATE_INS', 'WORK_TYPE',
61+
'AREA_BENEFITED', 'OTHER_WORKS', 'P_CONTRI', 'F_CONTRI',
62+
'EST_TOTAL', 'INSP', 'SITE_APP', 'APP_DATE', 'PLANTATIONS', 100, 50000,
63+
10000, 100, 5000000, 'VERIFIER']
64+
);
65+
66+
await connection.commit();
67+
console.log("All data inserted successfully with form_id:", formId);
68+
} catch (err) {
69+
await connection.rollback();
70+
console.error("Transaction failed:", err);
71+
} finally {
72+
await connection.end();
73+
}
74+
}

0 commit comments

Comments
 (0)