Skip to content

Commit

Permalink
set mysql utc timezone in knex
Browse files Browse the repository at this point in the history
  • Loading branch information
TimurRin committed Nov 21, 2024
1 parent 36d0463 commit bfba13b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/config/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const knexDbInit = knex({
host: process.env.SNAPCRUD_DB_HOST || "localhost",
password: process.env.SNAPCRUD_DB_PASSWORD || "",
port: parseInt(process.env.SNAPCRUD_DB_PORT || "3306") || 3306,
timezone: "UTC",
user: process.env.SNAPCRUD_DB_USER || "root",
},
pool: { max: 10, min: 0 },
Expand All @@ -23,6 +24,7 @@ export default knex({
host: process.env.SNAPCRUD_DB_HOST || "localhost",
password: process.env.SNAPCRUD_DB_PASSWORD || "",
port: parseInt(process.env.SNAPCRUD_DB_PORT || "3306") || 3306,
timezone: "UTC",
user: process.env.SNAPCRUD_DB_USER || "root",
},
pool: { max: 10, min: 0 },
Expand Down
2 changes: 1 addition & 1 deletion src/config/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function getConfig(): Promise<Config> {
try {
config = JSON.parse(await fs.readFile(configPath, "utf8"));
if (config == null) {
config = { };
config = {};
}
if (config.tables == null) {
config.tables = [];
Expand Down
27 changes: 13 additions & 14 deletions src/services/getTableEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function getTableEntity(
const columnType = columns.find((c) => c.Field === column)?.Type;
let inputType = "text";
let inputAttributes = "";
let inputElement = "";
let columnValue = entity[column];
Expand All @@ -78,39 +79,37 @@ export async function getTableEntity(
}
inputType = "datetime-local";
inputAttributes = `value="${columnValue}"`;
return `
<div>
<p><label for="${column}">${column}</label></p>
<input type="${inputType}" id="${column}" name="${column}" ${inputAttributes} ${primaryKeys.includes(column) ? "disabled" : ""}>
</div>
inputElement = `
<input type="${inputType}" id="${column}" name="${column}" ${inputAttributes} ${primaryKeys.includes(column) ? "disabled" : ""}>
`;
} else if (columnType.includes("enum")) {
const enumValues = columnType
.replace("enum(", "")
.replace(")", "")
.split(",");
inputAttributes = `value="${entity[column]}"`;
return `
<div>
<p><label for="${column}">${column}</label></p>
<select id="${column}" name="${column}" ${primaryKeys.includes(column) ? "disabled" : ""}>
${enumValues.map((value) => `<option value="${value}" ${entity[column] === value ? "selected" : ""}>${value}</option>`).join("")}
</select>
</div>
inputElement = `
<select id="${column}" name="${column}" ${primaryKeys.includes(column) ? "disabled" : ""}>
${enumValues.map((value) => `<option value="${value}" ${entity[column] === value ? "selected" : ""}>${value}</option>`).join("")}
</select>
`;
} else if (columnType.includes("bool")) {
inputType = "checkbox";
inputAttributes = `value="${entity[column]}" ${entity[column] === 1 ? "checked" : ""}`;
} else {
inputElement = `
<input type="${inputType}" id="${column}" name="${column}" value="${columnValue}" autocomplete="off" ${primaryKeys.includes(column) ? "disabled" : ""} ${inputAttributes}>
`;
}
return `
<div>
<p><label for="${column}">${column}</label></p>
<input type="${inputType}" id="${column}" name="${column}" value="${columnValue}" autocomplete="off" ${primaryKeys.includes(column) ? "disabled" : ""} ${inputAttributes}>
${inputElement}
</div>
`;
})
.join("")}
.join("")}
<button type="submit">Save</button>
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/types/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface Config {
displayAllTables?: boolean,
displayAllTables?: boolean;
tables?: {
displayAllColumns?: boolean;
editableColumns?: string[];
Expand Down

0 comments on commit bfba13b

Please sign in to comment.