Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

テーブル機能を実装 #6

Merged
merged 12 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function App({ Component, pageProps }: AppProps) {
return (
<>
<Header />
<Component {...pageProps} />;
<Component {...pageProps} />
</>
);
}
43 changes: 30 additions & 13 deletions pages/serverinfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ import { Container, Row, Table } from "react-bootstrap";
type Props = {
dbMbSizes: { name: string; mbSize: number }[];
storageMbSize: number;
error?: string;
};

const ServerInfoPage = ({ dbMbSizes }: Props) => {
const ServerInfoPage = ({ dbMbSizes, error }: Props) => {
if (error)
return (
<Container>
<Row>
<p style={{ color: "red" }}>{error}</p>
</Row>
</Container>
);
return (
<Container>
<Row>
Expand Down Expand Up @@ -36,24 +45,32 @@ const ServerInfoPage = ({ dbMbSizes }: Props) => {
export default ServerInfoPage;

export const getServerSideProps: GetServerSideProps = async (context) => {
const rows = await queryDb(`SELECT
try {
const rows = await queryDb(`SELECT
table_schema, sum(data_length+index_length) /1024 /1024 AS MB
FROM
information_schema.tables
GROUP BY
table_schema
ORDER BY
sum(data_length+index_length) DESC;`);
const dbMbSizes = rows.map((r) => {
return { name: r.TABLE_SCHEMA, mbSize: r.MB };
});
console.log(dbMbSizes);
const props: Props = {
dbMbSizes,
storageMbSize: 0,
};
const dbMbSizes = rows.map((r) => {
return { name: r.TABLE_SCHEMA, mbSize: r.MB };
});
console.log(dbMbSizes);
const props: Props = {
dbMbSizes,
storageMbSize: 0,
};

return {
props: props,
};
return {
props: props,
};
} catch (e: any) {
return {
props: {
error: e.message,
},
};
}
};
Loading
Loading