-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lunox-event): driver for typeorm and drizzle (#65)
* feat(lunox-event): typeorm connection * test(lunox-mail): using typeorm connection * feat(lunox-event-typeorm): add queue job and failed job models * feat(preset): update config for preset that using typeorm * test(lunox-event-typeorm): queue using mysql, sqlite and postgre * test(lunox-event-typeorm): precise test for retry after failed job * feat(lunox-event-drizzle): drizzle driver for lunoxjs-event * chore: install nx and sync dependencies * chore: build and test script using nx
- Loading branch information
Showing
89 changed files
with
2,070 additions
and
756 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
PG_PORT=5432 | ||
PG_NAME=lunox | ||
PG_USER=postgres | ||
PG_PASSWORD=postgres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
node_modules/ | ||
.env | ||
.nx/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
version: '3.8' | ||
services: | ||
lunox-db: | ||
container_name: lunox-db | ||
image: postgres:16 | ||
ports: | ||
- ${PG_PORT}:5432 | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: ${PG_PASSWORD} | ||
POSTGRES_PG: ${PG_NAME} | ||
PGDATA: /var/lib/postgresql/data | ||
networks: | ||
lunox-net: | ||
volumes: | ||
- postgres:/var/lib/postgresql/data | ||
restart: unless-stopped | ||
|
||
|
||
networks: | ||
lunox-net: | ||
driver: bridge | ||
ipam: | ||
driver: default | ||
volumes: | ||
postgres: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"tasksRunnerOptions": { | ||
"default": { | ||
"runner": "nx/tasks-runners/default", | ||
"options": { | ||
"cacheableOperations": ["build", "test"] | ||
} | ||
} | ||
}, | ||
"targetDefaults": { | ||
"build": { | ||
"dependsOn": ["^build"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
packages/lunox-auth/test/Feature/auth.session.typeorm.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import TestCase from "../TestCase"; | ||
import { describe, test, expect } from "vitest"; | ||
import User from "../app/Model/eloquent/User"; | ||
import User from "../app/Model/typeorm/User"; | ||
import { DB } from "@lunoxjs/typeorm"; | ||
|
||
TestCase.provider = "typeorm"; | ||
TestCase.make(); | ||
describe("Auth Session Test", () => { | ||
test("can run Application", async () => { | ||
expect(config("app.name")).toBe("@lunoxjs/auth"); | ||
expect(await User.query().first()).toMatchObject({ | ||
expect(await DB.use(User).findOne({where: { email: "[email protected]" }})).toMatchObject({ | ||
email: "[email protected]", | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,9 @@ | ||
export default { | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Default Database Connection Name | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here you may specify which of the database connections below you wish | ||
| to use as your default connection for all database work. Of course | ||
| you may use many connections at once using the Database library. | ||
| | ||
*/ | ||
|
||
default: env("DB_CONNECTION", "sqlite"), | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Database Connections | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here are each of the database connections setup for your application. | ||
| Of course, examples of configuring each database platform that is | ||
| supported by Laravel is shown below to make development simple. | ||
| | ||
| | ||
| All database work in Laravel is done through the PHP PDO facilities | ||
| so make sure you have the driver for your particular database of | ||
| choice installed on your machine before you begin development. | ||
| | ||
*/ | ||
|
||
default: "sqlite", | ||
connections: { | ||
sqlite: { | ||
driver: "sqlite", | ||
database: env("DB_DATABASE", base_path("database/database.sqlite")), | ||
}, | ||
|
||
mysql: { | ||
driver: "mysql", | ||
host: env("DB_HOST", "127.0.0.1"), | ||
port: env("DB_PORT", "3306"), | ||
database: env("DB_DATABASE", "lunox"), | ||
username: env("DB_USERNAME", "@lunoxjs/core"), | ||
password: env("DB_PASSWORD", ""), | ||
charset: "utf8mb4", | ||
collation: "utf8mb4_unicode_ci", | ||
prefix: "", | ||
prefix_indexes: true, | ||
strict: true, | ||
engine: null, | ||
}, | ||
pgsql: { | ||
driver: "pgsql", | ||
url: env("DATABASE_URL"), | ||
host: env("DB_HOST", "127.0.0.1"), | ||
port: env("DB_PORT", "5432"), | ||
database: env("DB_DATABASE", "forge"), | ||
username: env("DB_USERNAME", "forge"), | ||
password: env("DB_PASSWORD", ""), | ||
charset: "utf8", | ||
prefix: "", | ||
prefix_indexes: true, | ||
schema: "public", | ||
sslmode: "prefer", | ||
}, | ||
|
||
sqlsrv: { | ||
driver: "sqlsrv", | ||
url: env("DATABASE_URL"), | ||
host: env("DB_HOST", "localhost"), | ||
port: env("DB_PORT", "1433"), | ||
database: env("DB_DATABASE", "forge"), | ||
username: env("DB_USERNAME", "forge"), | ||
password: env("DB_PASSWORD", ""), | ||
charset: "utf8", | ||
prefix: "", | ||
prefix_indexes: true, | ||
}, | ||
}, | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Migration Repository Table | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This table keeps track of all the migrations that have already run for | ||
| your application. Using this information, we can determine which of | ||
| the migrations on disk haven't actually been run in the database. | ||
| | ||
*/ | ||
|
||
migrations: "migrations", | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Redis Databases | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Redis is an open source, fast, and advanced key-value store that also | ||
| provides a richer body of commands than a typical key-value system | ||
| such as APC or Memcached. Laravel makes it easy to dig right in. | ||
| | ||
*/ | ||
|
||
redis: { | ||
client: env("REDIS_CLIENT", "phpredis"), | ||
|
||
options: { | ||
cluster: env("REDIS_CLUSTER", "redis"), | ||
}, | ||
|
||
default: { | ||
url: env("REDIS_URL"), | ||
host: env("REDIS_HOST", "127.0.0.1"), | ||
password: env("REDIS_PASSWORD", null), | ||
port: env("REDIS_PORT", "6379"), | ||
database: env("REDIS_DB", "0"), | ||
}, | ||
|
||
cache: { | ||
url: env("REDIS_URL"), | ||
host: env("REDIS_HOST", "127.0.0.1"), | ||
password: env("REDIS_PASSWORD", null), | ||
port: env("REDIS_PORT", "6379"), | ||
database: env("REDIS_CACHE_DB", "1"), | ||
database: base_path("database/database.sqlite") | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules/ | ||
dist/ | ||
.env | ||
test/database.sqlite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="@lunoxjs/core/global" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./dist/models/mysql" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"name": "@lunoxjs/event-drizzle", | ||
"version": "2.0.0-beta.3.5.0", | ||
"description": "Drizzle Connection for @lunoxjs/event", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": "./dist/index.js", | ||
"./dist/*": "./dist/*", | ||
"./mysql": "./dist/models/mysql/index.js", | ||
"./sqlite": "./dist/models/sqlite/index.js", | ||
"./postgre": "./dist/models/postgre/index.js" | ||
}, | ||
"files": [ | ||
"dist/*" | ||
], | ||
"scripts": { | ||
"build": "lunox prod", | ||
"dev": "lunox dev", | ||
"test": "vitest" | ||
}, | ||
"keywords": [ | ||
"lunoxjs", | ||
"event", | ||
"scheduler", | ||
"queue", | ||
"drizzle" | ||
], | ||
"author": { | ||
"name": "Akhmad Salafudin", | ||
"email": "[email protected]", | ||
"url": "https://github.com/axmad386" | ||
}, | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@lunoxjs/core": "workspace:*", | ||
"@lunoxjs/drizzle": "workspace:*", | ||
"@lunoxjs/event": "workspace:*", | ||
"@lunoxjs/test": "workspace:*", | ||
"@types/better-sqlite3": "^7.6.9", | ||
"@types/pg": "^8.11.6", | ||
"better-sqlite3": "^9.3.0", | ||
"dayjs": "^1.11.10", | ||
"drizzle-orm": "^0.29.1", | ||
"mysql2": "^3.6.5", | ||
"pg": "^8.11.3", | ||
"typescript": "^5.3.2", | ||
"vitest": "^0.34.6" | ||
}, | ||
"peerDependencies": { | ||
"@lunoxjs/core": "workspace:*", | ||
"@lunoxjs/drizzle": "workspace:*", | ||
"@lunoxjs/event": "workspace:*" | ||
}, | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./dist/models/postgre" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./dist/models/sqlite" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { DB } from "@lunoxjs/drizzle"; | ||
import { QueueJobSchema, QueueJobFailedSchema } from "@lunoxjs/event/contracts"; | ||
import { BaseQueueConnection } from "@lunoxjs/event"; | ||
import { and, asc, eq, lte } from "drizzle-orm"; | ||
|
||
class Connection extends BaseQueueConnection { | ||
protected async storeJob( | ||
data: Pick<QueueJobSchema, "queue" | "payload" | "available_at">, | ||
): Promise<void> { | ||
await (DB as any).insert(this.config.model.job).values(data); | ||
} | ||
|
||
protected async updateJob(queueJob: QueueJobSchema): Promise<void> { | ||
await (DB as any).update(this.config.model.job) | ||
.set(queueJob) | ||
.where(eq(this.config.model.job.id, queueJob.id)); | ||
} | ||
|
||
protected async removeJob(queueJob: QueueJobSchema): Promise<void> { | ||
await (DB as any).delete(this.config.model.job).where( | ||
eq(this.config.model.job.id, queueJob.id), | ||
); | ||
} | ||
|
||
protected async storeFailedJob( | ||
data: Pick< | ||
QueueJobFailedSchema, | ||
"queue" | "payload" | "failed_at" | "exception" | ||
>, | ||
): Promise<void> { | ||
await (DB as any).insert(this.config.model.failedJob).values(data); | ||
} | ||
|
||
protected async getLastJob(queue: string): Promise<QueueJobSchema | null> { | ||
const res = await (DB as any).select() | ||
.from(this.config.model.job) | ||
.where( | ||
and( | ||
eq(this.config.model.job.queue, queue), | ||
lte(this.config.model.job.available_at, new Date()), | ||
), | ||
) | ||
.orderBy(asc(this.config.model.job.id)) | ||
.limit(1); | ||
return res?.[0] as QueueJobSchema | null; | ||
} | ||
} | ||
export default Connection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import Connection from "./Connection"; | ||
export { Connection }; |
Oops, something went wrong.