Skip to content

Commit

Permalink
移除sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
cweijan committed Jul 14, 2022
1 parent 8d2b05f commit 91c865d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
5 changes: 1 addition & 4 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@
"body-parser": "^1.19.0",
"express": "^4.17.1",
"mysql2": "^2.3.2",
"pg": "^8.7.1",
"sqlite": "^4.0.23",
"sqlite3": "^5.0.2"
"pg": "^8.7.1"
},
"devDependencies": {
"@types/body-parser": "^1.19.0",
"@types/express": "^4.17.9",
"@types/node": "^14.14.9",
"@types/sqlite3": "^3.1.7",
"ts-node": "^9.0.0",
"tshot": "0.0.2",
"typescript": "^4.1.2"
Expand Down
50 changes: 24 additions & 26 deletions server/src/service/revision.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sqlite3 from 'sqlite3'
import { open } from 'sqlite'
import { Application } from 'express';
import { pressError } from './uti';
import { NewProjectVersion } from '../request/requestDTO';
Expand All @@ -13,40 +11,40 @@ const dataDDL = `CREATE TABLE revision_data(
);`

function openDb() {
return open({
filename: __dirname + '/revision_data.db',
driver: sqlite3.Database
})
// return open({
// filename: __dirname + '/revision_data.db',
// driver: sqlite3.Database
// })
}

async function initRevision() {
const db = await openDb();
const revisionData = await db.get(`SELECT name, type FROM sqlite_master WHERE type="table" AND name='revision_data';`);
if (revisionData) return;
db.exec(dataDDL)
// const db = await openDb();
// const revisionData = await db.get(`SELECT name, type FROM sqlite_master WHERE type="table" AND name='revision_data';`);
// if (revisionData) return;
// db.exec(dataDDL)
}

export async function bindRevisionApi(app: Application) {

initRevision()
// initRevision()

app.get('/api/project/version', async (req, res, next) => {
pressError(res, async () => {
const projectId = req.query.projectId;
const db = await openDb();
const versionData=await db.all(`select * from revision_data where project_id=${projectId}`)
res.json(versionData);
})
});
// app.get('/api/project/version', async (req, res, next) => {
// pressError(res, async () => {
// const projectId = req.query.projectId;
// const db = await openDb();
// const versionData=await db.all(`select * from revision_data where project_id=${projectId}`)
// res.json(versionData);
// })
// });

app.post('/api/project/version/new', async function (req, res, next) {
pressError(res, async () => {
const option: NewProjectVersion = req.body;
const db = await openDb();
// app.post('/api/project/version/new', async function (req, res, next) {
// pressError(res, async () => {
// const option: NewProjectVersion = req.body;
// const db = await openDb();

db.run(`insert into revision_data(project_id,version,remark,content) values ('${option.projectId}','${option.version}','${option.remark}','${option.content}')`)
// db.run(`insert into revision_data(project_id,version,remark,content) values ('${option.projectId}','${option.version}','${option.remark}','${option.content}')`)

})
});
// })
// });

}

0 comments on commit 91c865d

Please sign in to comment.