Skip to content

Commit 2b6caf4

Browse files
committed
update codebase
1 parent 8507662 commit 2b6caf4

File tree

7 files changed

+111
-27
lines changed

7 files changed

+111
-27
lines changed

package-lock.json

+8-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"lit-html": "^2.0.0",
2626
"nodemon": "^2.0.22",
2727
"ts-jest": "^29.1.0",
28-
"ts-node": "^10.9.1"
28+
"ts-node": "^10.9.1",
29+
"tslib": "^2.6.1"
2930
},
3031
"dependencies": {
3132
"@types/express": "^4.17.17",
@@ -51,4 +52,4 @@
5152
"coverageDirectory": "../coverage",
5253
"testEnvironment": "node"
5354
}
54-
}
55+
}

src/client/src/client.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { TableDocument, TableFieldDocument } from "component/table";
2+
import { parseCommentTable } from "../../lib/parser/comment_parser";
3+
import { exampleStrings } from "../test/example/sql";
24

3-
let tableDoc = document.createElement('table-document');
5+
let tableDoc = document.createElement("table-document");
6+
7+
let exampleInput = exampleStrings;
8+
9+
let parsedData = parseCommentTable(exampleInput);
410

511
console.log(tableDoc);
612

7-
console.log("-_-;;")
13+
console.log(parsedData);

src/client/test/example/sql.ts

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
export const exampleStrings = `
2+
CREATE DATABASE SqldocExampleDatabase DEFAULT CHARACTER SET = 'utf8' COLLATE= 'utf8_general_ci';
3+
use SqldocExampleDatabase;
4+
5+
/**
6+
* @table [InnoDB] User
7+
* This table is user Table.
8+
* This table is only for user. Never use in another service.
9+
* Only Read. but Only write in User Service.
10+
*
11+
* @tableColumn {BIGINT UNSIGNED} [PRIMARY KEY, AUTO_INCREMENT] id
12+
* This is just for clustred index. don't use for relation.
13+
* later this database will be sharded.
14+
*
15+
* @tableColumn {TINYINT UNSIGNED} [DEFAULT=0] type
16+
* 0 is Anonymous user.
17+
* 1 is Authenticated user.
18+
* 2 is Admin.
19+
* 3 is Super Admin.
20+
* @tableColumn {DATETIME} [DEFAULT=CURRENT_TIMESTAMP] joinDate
21+
* Just signed date.
22+
* @tableColumn {VARCHAR(64)} [UNIQUE, NOT NULL] userEmail
23+
* For resetting password.
24+
* @tableColumn {VARCHAR(24)} [UNIQUE, NOT NULL] username
25+
* For login.
26+
* @tableColumn {VARCHAR(24)} [NOT NULL] nickname
27+
* For exposing to other.
28+
* @tableColumn {VARCHAR(24)} [UNIQUE, NOT NULL] password
29+
* This column is stored as encrypted value.
30+
*/
31+
CREATE TABLE \`User\`(
32+
\`id\` BIGINT(24) UNSIGNED PRIMARY KEY AUTO_INCREMENT,
33+
\`type\` TINYINT UNSIGNED NOT NULL DEFAULT 0,
34+
\`joinDate\` DATETIME DEFAULT CURRENT_TIMESTAMP,
35+
\`userEmail\` VARCHAR(64) UNIQUE NOT NULL
36+
\`username\` VARCHAR(24) UNIQUE NOT NULL,
37+
\`nickname\` VARCHAR(24) NOT NULL,
38+
\`password\` VARCHAR(64) NOT NULL,
39+
) ENGINE = InnoDB;
40+
41+
/**
42+
* @table [InnoDB] Page
43+
* This is for storing content written by User.
44+
*
45+
* @tableColumn {BIGINT UNSIGNED} [PRIMARY KEY, AUTO_INCREMENT] id
46+
* This is just for clustred index. don't use for relation.
47+
* later this database will be sharded.
48+
* use userId with createDate instead of this.
49+
* @tableColumn {BIGINT UNSIGNED} [FOREIGN KEY] userId
50+
* @tableColumn {DATETIME} [DEFAULT=CURRENT_TIMESTAMP] text
51+
* @tableColumn {VARCHAR(24)} [UNIQUE, NOT NULL] createDate
52+
*/
53+
CREATE TABLE \`Page\`(
54+
\`id\` BIGINT(24) UNSIGNED PRIMARY KEY AUTO_INCREMENT,
55+
\`userId\` BIGINT(24) UNSIGNED,
56+
\`title\` VARCHAR(24) NOT NULL,
57+
\`text\` TEXT default NULL,
58+
\`createDate\` DATETIME DEFAULT CURRENT_TIMESTAMP
59+
60+
CONSTRAINT \`FK_Page_User\`
61+
FOREIGN KEY(\`userId\`) REFERENCES User(\`id\`)
62+
ON DELETE CASCADE
63+
) ENGINE = InnoDB;
64+
`;

src/lib/parser/comment_parser.ts

+4-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import fs from "fs";
2-
import path from "path";
1+
// import fs from "fs";
2+
// import path from "path";
33
import {
44
COMMENT_SYMBOL_LIST,
55
ParsedCommentSymbol,
@@ -10,8 +10,8 @@ import {
1010
TableDocument,
1111
} from "./types/common";
1212

13-
export function parseCommentTable(input: ParserInputParameter) {
14-
const strings = getRawStrings(input);
13+
export function parseCommentTable(input: string) {
14+
const strings = input;
1515
const comments: ParsedCommentSymbol[] = [];
1616

1717
const result: TableDocument[] = [];
@@ -200,16 +200,3 @@ function prepareComments(inputString: string) {
200200

201201
return _comments;
202202
}
203-
204-
// Helper
205-
function getRawStrings(inputString: ParserInputParameter) {
206-
if (inputString.inputFilePath) {
207-
const filePath = path.resolve(
208-
inputString.callerFilePath || "",
209-
inputString.inputFilePath
210-
);
211-
return fs.readFileSync(filePath, "utf-8");
212-
}
213-
214-
return inputString.inputText;
215-
}

test/unit/parse-sql.spec.ts

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
1+
import path from "path";
2+
import fs from "fs";
3+
import { ParserInputParameter } from "lib/parser/types/common";
14
import { parseCommentTable } from "../../src/lib/parser/comment_parser";
25

6+
// Helper
7+
function getRawStrings(inputString: ParserInputParameter) {
8+
if (inputString.inputFilePath) {
9+
const filePath = path.resolve(
10+
inputString.callerFilePath || "",
11+
inputString.inputFilePath
12+
);
13+
return fs.readFileSync(filePath, "utf-8");
14+
}
15+
16+
return inputString.inputText;
17+
}
18+
319
describe("Parsing SQL", () => {
420
it("Should parse a sql file", async () => {
5-
const parsed_table = parseCommentTable({
6-
inputFilePath: "../example/sqls/table-example.sql",
7-
callerFilePath: __dirname,
8-
});
21+
const parsed_table = parseCommentTable(
22+
getRawStrings({
23+
inputFilePath: "../example/sqls/table-example.sql",
24+
callerFilePath: __dirname,
25+
})!
26+
);
927

1028
expect(parsed_table.length).toEqual(2);
1129
});

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"esModuleInterop": true,
1414
"skipLibCheck": true,
1515
"forceConsistentCasingInFileNames": true,
16-
"downlevelIteration": true
16+
"downlevelIteration": true,
17+
"importHelpers": true,
1718
},
1819
"include":["./**/*.ts"],
1920
"exclude": [

0 commit comments

Comments
 (0)