Skip to content

Commit

Permalink
feat(vercel): compat postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
lizheming committed Dec 8, 2020
1 parent 93e3692 commit 2b70144
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 4 deletions.
47 changes: 47 additions & 0 deletions assets/waline.pgsql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

CREATE SEQUENCE wl_comment_seq;

CREATE TABLE wl_comment (
id int check (id > 0) NOT NULL DEFAULT NEXTVAL ('wl_comment_seq'),
comment text,
insertedAt timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ip varchar(100) DEFAULT '',
link varchar(255) DEFAULT NULL,
mail varchar(255) DEFAULT NULL,
nick varchar(255) DEFAULT NULL,
pid int DEFAULT NULL,
rid int DEFAULT NULL,
status varchar(50) NOT NULL DEFAULT '',
ua text,
url varchar(255) DEFAULT NULL,
createdAt timestamp(0) NULL DEFAULT CURRENT_TIMESTAMP,
updatedAt timestamp(0) NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
) ;


CREATE SEQUENCE wl_counter_seq;

CREATE TABLE wl_counter (
id int check (id > 0) NOT NULL DEFAULT NEXTVAL ('wl_counter_seq'),
time int DEFAULT NULL,
url varchar(255) NOT NULL DEFAULT '',
createdAt timestamp(0) NULL DEFAULT CURRENT_TIMESTAMP,
updatedAt timestamp(0) NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
) ;


CREATE SEQUENCE wl_users_seq;

CREATE TABLE wl_users (
id int check (id > 0) NOT NULL DEFAULT NEXTVAL ('wl_users_seq'),
display_name varchar(255) NOT NULL DEFAULT '',
email varchar(255) NOT NULL DEFAULT '',
password varchar(255) NOT NULL DEFAULT '',
type varchar(50) NOT NULL DEFAULT '',
url varchar(255) DEFAULT NULL,
createdAt timestamp(0) NULL DEFAULT CURRENT_TIMESTAMP,
updatedAt timestamp(0) NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
) ;
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"think-logger3": "^1.0.0",
"think-model": "^1.5.1",
"think-model-mysql": "^1.1.4",
"think-model-postgresql": "^1.1.4",
"think-model-postgresql": "^1.1.5",
"think-model-sqlite": "^1.2.1",
"think-mongo": "^2.1.0",
"think-router-rest": "^1.0.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if(think.env === 'cloudbase' || TCB_ENV) {
storage = 'mongodb';
jwtKey = jwtKey || MONGO_PASSWORD;
} else if (PG_DB) {
storage = 'mysql';
storage = 'postgresql';
jwtKey = jwtKey || PG_PASSWORD;
} else if (SQLITE_PATH) {
storage = 'mysql';
Expand Down
9 changes: 7 additions & 2 deletions packages/server/src/service/storage/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ module.exports = class extends Base {
continue;
}

if(Array.isArray(filter[k]) && think.isDate(filter[k][1])) {
filter[k][1] = think.datetime(filter[k][1]);
if(Array.isArray(filter[k])) {
if(filter[k][0] === 'IN' && !filter[k][1].length) {
continue;
} if(think.isDate(filter[k][1])) {
filter[k][1] = think.datetime(filter[k][1]);
}
}

where[k] = filter[k];
}
return where;
Expand Down
16 changes: 16 additions & 0 deletions packages/server/src/service/storage/postgresql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const MySQL = require('./mysql');

module.exports = class extends MySQL {
model(tableName) {
return super.model(tableName.toLowerCase());
}

async count(...args) {
let result = await super.count(...args);
if(!Array.isArray(result)) {
return result;
}

return result[0].think_count;
}
}

0 comments on commit 2b70144

Please sign in to comment.