diff --git a/.cspell.json b/.cspell.json
index ecaabad6060..eba7db40f5c 100644
--- a/.cspell.json
+++ b/.cspell.json
@@ -393,7 +393,9 @@
"Desterrro",
"Chetan",
"chetan",
- "Yostorono"
+ "Yostorono",
+ "sarif",
+ "SARIF"
],
"useGitignore": true,
"ignorePaths": [
diff --git a/.env.docker b/.env.docker
index 12cb10ba211..6c4c7bce821 100644
--- a/.env.docker
+++ b/.env.docker
@@ -30,8 +30,8 @@ CLIENT_BASE_URL=http://localhost:4200
#set to Website Platform
PLATFORM_WEBSITE_URL=https://gauzy.co
-# DB_TYPE: sqlite | postgres
-DB_TYPE=sqlite
+# DB_TYPE: sqlite | postgres | better-sqlite3
+DB_TYPE=better-sqlite3
DB_SYNCHRONIZE=false
# Below are PostgreSQL Connection Parameters
diff --git a/.env.local b/.env.local
index ec2482079a2..884af5c44f7 100644
--- a/.env.local
+++ b/.env.local
@@ -30,8 +30,8 @@ CLIENT_BASE_URL=http://localhost:4200
#set to Website Platform
PLATFORM_WEBSITE_URL=https://gauzy.co
-# DB_TYPE: sqlite | postgres
-DB_TYPE=sqlite
+# DB_TYPE: sqlite | postgres | better-sqlite3
+DB_TYPE=better-sqlite3
DB_SYNCHRONIZE=false
# Below are PostgreSQL Connection Parameters
diff --git a/.env.sample b/.env.sample
index 449079d46f0..1f686561b6f 100644
--- a/.env.sample
+++ b/.env.sample
@@ -15,8 +15,8 @@ CLIENT_BASE_URL=http://localhost:4200
#set to Website Platform
PLATFORM_WEBSITE_URL=https://gauzy.co
-# DB_TYPE: sqlite | postgres
-DB_TYPE=sqlite
+# DB_TYPE: sqlite | postgres | better-sqlite3
+DB_TYPE=better-sqlite3
# PostgreSQL Connection Parameters
# DB_HOST=localhost
diff --git a/apps/api/src/plugin-config.ts b/apps/api/src/plugin-config.ts
index d64b7f8cb35..e8e41d6c54b 100644
--- a/apps/api/src/plugin-config.ts
+++ b/apps/api/src/plugin-config.ts
@@ -129,5 +129,26 @@ function getDbConfig(): DataSourceOptions {
logger: 'file', // Removes console logging, instead logs all queries in a file ormlogs.log
synchronize: process.env.DB_SYNCHRONIZE === 'true' ? true : false, // We are using migrations, synchronize should be set to false.
};
+ case 'better-sqlite3':
+ const betterSqlitePath =
+ process.env.DB_PATH ||
+ path.join(
+ path.resolve('.', ...['apps', 'api', 'data']),
+ 'gauzy.sqlite3'
+ );
+
+ return {
+ type: dbType,
+ database: betterSqlitePath,
+ logging: 'all',
+ logger: 'file', // Removes console logging, instead logs all queries in a file ormlogs.log
+ synchronize: process.env.DB_SYNCHRONIZE === 'true', // We are using migrations, synchronize should be set to false.
+ prepareDatabase: (db) => {
+ if (!process.env.IS_ELECTRON) {
+ // Enhance performance
+ db.pragma('journal_mode = WAL');
+ }
+ }
+ };
}
}
diff --git a/apps/desktop-timer/src/index.ts b/apps/desktop-timer/src/index.ts
index 531a200cb64..f8e20fffb69 100644
--- a/apps/desktop-timer/src/index.ts
+++ b/apps/desktop-timer/src/index.ts
@@ -392,7 +392,7 @@ app.on('ready', async () => {
if (!settings) {
launchAtStartup(true, false);
}
- if (provider.dialect === 'sqlite') {
+ if (['sqlite', 'better-sqlite'].includes(provider.dialect)) {
try {
const res = await knex.raw(`pragma journal_mode = WAL;`);
console.log(res);
@@ -600,46 +600,13 @@ ipcMain.on('restart_and_update', () => {
ipcMain.on('check_database_connection', async (event, arg) => {
try {
- const provider = arg.db;
- let databaseOptions;
- if (provider === 'postgres' || provider === 'mysql') {
- databaseOptions = {
- client: provider === 'postgres' ? 'pg' : 'mysql',
- connection: {
- host: arg[provider].dbHost,
- user: arg[provider].dbUsername,
- password: arg[provider].dbPassword,
- database: arg[provider].dbName,
- port: arg[provider].dbPort,
- },
- };
- } else {
- databaseOptions = {
- client: 'sqlite3',
- connection: {
- filename: sqlite3filename,
- },
- };
- }
- const dbConn = require('knex')(databaseOptions);
- await dbConn.raw('select 1+1 as result');
+ const driver = await provider.check(arg);
event.sender.send('database_status', {
status: true,
- message:
- provider === 'postgres'
- ? TranslateService.instant(
- 'TIMER_TRACKER.DIALOG.CONNECTION_DRIVER',
- { driver: 'PostgresSQL' }
- )
- : provider === 'mysql'
- ? TranslateService.instant(
- 'TIMER_TRACKER.DIALOG.CONNECTION_DRIVER',
- { driver: 'MySQL' }
- )
- : TranslateService.instant(
- 'TIMER_TRACKER.DIALOG.CONNECTION_DRIVER',
- { driver: 'SQLite' }
- ),
+ message: TranslateService.instant(
+ 'TIMER_TRACKER.DIALOG.CONNECTION_DRIVER',
+ { driver }
+ ),
});
} catch (error) {
event.sender.send('database_status', {
diff --git a/apps/desktop/src/index.ts b/apps/desktop/src/index.ts
index 924616e924a..47161e5ebed 100644
--- a/apps/desktop/src/index.ts
+++ b/apps/desktop/src/index.ts
@@ -233,7 +233,10 @@ async function startServer(value, restart = false) {
if (value.db === 'sqlite') {
process.env.DB_PATH = sqlite3filename;
process.env.DB_TYPE = 'sqlite';
- } else {
+ }else if(value.db === 'better-sqlite') {
+ process.env.DB_PATH = sqlite3filename;
+ process.env.DB_TYPE = 'better-sqlite3';
+ }else {
process.env.DB_TYPE = 'postgres';
process.env.DB_HOST = value['postgres']?.dbHost;
process.env.DB_PORT = value['postgres']?.dbPort;
@@ -462,7 +465,7 @@ app.on('ready', async () => {
splashScreen = new SplashScreen(pathWindow.timeTrackerUi);
await splashScreen.loadURL();
splashScreen.show();
- if (provider.dialect === 'sqlite') {
+ if (['sqlite', 'better-sqlite'].includes(provider.dialect)) {
try {
const res = await knex.raw(`pragma journal_mode = WAL;`)
console.log(res);
@@ -698,34 +701,12 @@ ipcMain.on('restart_and_update', () => {
ipcMain.on('check_database_connection', async (event, arg) => {
try {
- const provider = arg.db;
- let databaseOptions;
- if (provider === 'postgres') {
- databaseOptions = {
- client: 'pg',
- connection: {
- host: arg[provider].dbHost,
- user: arg[provider].dbUsername,
- password: arg[provider].dbPassword,
- database: arg[provider].dbName,
- port: arg[provider].dbPort
- }
- };
- } else {
- databaseOptions = {
- client: 'sqlite',
- connection: {
- filename: sqlite3filename,
- },
- };
- }
- const dbConn = require('knex')(databaseOptions);
- await dbConn.raw('select 1+1 as result');
+ const driver = await provider.check(arg);
event.sender.send('database_status', {
status: true,
message: TranslateService.instant(
'TIMER_TRACKER.DIALOG.CONNECTION_DRIVER',
- { driver: provider === 'postgres' ? 'PostgresSQL' : 'SQLite' }
+ { driver }
)
});
} catch (error) {
diff --git a/apps/gauzy/src/app/@core/auth/auth-strategy.service.ts b/apps/gauzy/src/app/@core/auth/auth-strategy.service.ts
index 60aa48f9ee0..0e7b0c3b0c5 100644
--- a/apps/gauzy/src/app/@core/auth/auth-strategy.service.ts
+++ b/apps/gauzy/src/app/@core/auth/auth-strategy.service.ts
@@ -3,7 +3,7 @@ import { NbAuthResult, NbAuthStrategy } from '@nebular/auth';
import { ActivatedRoute } from '@angular/router';
import { catchError, filter, map, switchMap } from 'rxjs/operators';
import { Injectable } from '@angular/core';
-import { IUser, IAuthResponse } from '@gauzy/contracts';
+import { IUser, IAuthResponse, IUserLoginInput } from '@gauzy/contracts';
import { distinctUntilChange, isNotEmpty } from '@gauzy/common-angular';
import { NbAuthStrategyClass } from '@nebular/auth/auth.options';
import { AuthService } from '../services/auth.service';
@@ -102,7 +102,7 @@ export class AuthStrategy extends NbAuthStrategy {
rememberMe(data?: any) {
const rememberMe = !!data.rememberMe;
if (rememberMe) {
- this.cookieService.set('email', data.email);
+ this.cookieService.set('email', data.email?.trim());
this.cookieService.set('rememberMe', 'true');
} else {
this.cookieService.delete('rememberMe');
@@ -130,7 +130,7 @@ export class AuthStrategy extends NbAuthStrategy {
lastName: fullName
? fullName.split(' ').slice(-1).join(' ')
: null,
- email,
+ email: email?.trim(),
tenant,
tags,
},
@@ -296,7 +296,8 @@ export class AuthStrategy extends NbAuthStrategy {
}
}
- public login(loginInput): Observable {
+ public login(loginInput: IUserLoginInput): Observable {
+ loginInput.email = loginInput.email?.trim();
return this.authService.login(loginInput).pipe(
map((res: IAuthResponse) => {
let user, token, refresh_token;
diff --git a/apps/gauzy/src/app/@core/services/auth.service.ts b/apps/gauzy/src/app/@core/services/auth.service.ts
index daeda500f7e..86e5534a90d 100644
--- a/apps/gauzy/src/app/@core/services/auth.service.ts
+++ b/apps/gauzy/src/app/@core/services/auth.service.ts
@@ -18,10 +18,7 @@ import { API_PREFIX } from '../constants/app.constants';
@Injectable()
export class AuthService {
-
- constructor(
- private readonly http: HttpClient
- ) { }
+ constructor(private readonly http: HttpClient) {}
isAuthenticated(): Promise {
return firstValueFrom(
@@ -33,7 +30,7 @@ export class AuthService {
return this.http.post