-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPositionsVacant.bal
103 lines (96 loc) · 3.28 KB
/
PositionsVacant.bal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import ballerina/sql;
import ballerina/time;
public type PositionsVacant record {
int? id = ();
int office_id;
int job_id;
int amount;
string start_date;
string? end_date = ();
time:Utc last_updated = time:utcNow();
string notes;
};
public isolated function getPositionsVacants() returns PositionsVacant[]|error {
PositionsVacant[] positionsVacants = [];
stream<PositionsVacant, error?> resultStream = smsDBClient->query(
`SELECT
id ,
office_id ,
job_id ,
amount ,
start_date ,
end_date ,
last_updated ,
notes
FROM positions_vacant`
);
check from PositionsVacant positionsVacant in resultStream
do {
positionsVacants.push(positionsVacant);
};
check resultStream.close();
return positionsVacants;
}
public isolated function getPositionsVacant(int id) returns PositionsVacant|error {
PositionsVacant positionsVacant = check smsDBClient->queryRow(
`SELECT * FROM positions_vacant WHERE id = ${id}`
);
return positionsVacant;
}
public isolated function addPositionsVacant(PositionsVacant positionsVacant) returns int|error {
sql:ExecutionResult result = check smsDBClient->execute(`
INSERT INTO positions_vacant (
office_id ,
job_id ,
amount ,
start_date ,
end_date ,
last_updated ,
notes )
VALUES (
${positionsVacant.office_id},
${positionsVacant.job_id},
${positionsVacant.amount},
${positionsVacant.start_date},
${positionsVacant.end_date},
${positionsVacant.last_updated},
${positionsVacant.notes}
)
`);
int|string? lastInsertId = result.lastInsertId;
if lastInsertId is int {
return lastInsertId;
} else {
return error("Unable to obtain last insert ID for positions_vacant");
}
}
public isolated function updatePositionsVacant(PositionsVacant positionsVacant) returns int|error {
sql:ExecutionResult result = check smsDBClient->execute(`
UPDATE positions_vacant SET
office_id = ${positionsVacant.office_id},
job_id = ${positionsVacant.job_id},
amount = ${positionsVacant.amount},
start_date = ${positionsVacant.start_date},
end_date = ${positionsVacant.end_date},
last_updated = ${positionsVacant.last_updated},
notes = ${positionsVacant.notes}
WHERE id = ${positionsVacant.id}
`);
int|string? affectedRowCount = result.affectedRowCount;
if affectedRowCount is int {
return affectedRowCount;
} else {
return error("Unable to obtain last affected count for positions_vacant update");
}
}
isolated function deletePositionsVacant(int id) returns int|error {
sql:ExecutionResult result = check smsDBClient->execute(`
DELETE FROM positions_vacant WHERE id = ${id}
`);
int? affectedRowCount = result.affectedRowCount;
if affectedRowCount is int {
return affectedRowCount;
} else {
return error("Unable to obtain the affected row count for positions_vacant delete");
}
}