parent
c0777f77b5
commit
60bb9afa29
@ -0,0 +1,2 @@
|
||||
export * from '../../lib/src/module.ts'
|
||||
export * from '../../di/module.ts'
|
@ -0,0 +1,4 @@
|
||||
export { default as ConfigUnit } from '../../lib/src/unit/Config.ts'
|
||||
export { DatabaseUnit } from '../../orm/src/DatabaseUnit.ts'
|
||||
export { default as ControllerUnit } from '../../lib/src/unit/Controllers.ts'
|
||||
export { default as MiddlewareUnit } from '../../lib/src/unit/Middlewares.ts'
|
@ -0,0 +1,5 @@
|
||||
import { env } from '../../lib/src/unit/Scaffolding.ts';
|
||||
|
||||
export default {
|
||||
name: env('APP_NAME', 'Daton'),
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
import { env } from '../../../lib/src/unit/Scaffolding.ts';
|
||||
|
||||
export default {
|
||||
name: env('APP_NAME', 'Daton'),
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import {env} from "../../lib/src/unit/Scaffolding.ts";
|
||||
|
||||
export default {
|
||||
|
||||
connections: {
|
||||
default: {
|
||||
type: env('DB_TYPE', 'postgres'),
|
||||
user: env('DB_USERNAME', 'daton'),
|
||||
password: env('DB_PASSWORD'),
|
||||
database: env('DB_DATABASE', 'daton'),
|
||||
hostname: env('DB_HOSTNAME', 'localhost'),
|
||||
port: env('DB_PORT', 5432),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env -S deno run -c ./tsconfig.json --unstable --allow-read --allow-env --allow-net
|
||||
/* Main executable for the Daton app. */
|
||||
|
||||
import { make, Scaffolding, Application } from './bundle/daton.ts'
|
||||
import units from './units.ts'
|
||||
|
||||
/*
|
||||
* Let's get up and running. The scaffolding provides the bare minimum
|
||||
* amount of support required to get Daton up and running. The app handles
|
||||
* the rest.
|
||||
*/
|
||||
const scaffolding = make(Scaffolding)
|
||||
await scaffolding.up()
|
||||
|
||||
/*
|
||||
* Now, import the units and start the application. The units define each
|
||||
* modular piece of functionality that is managed by the Daton app.
|
||||
*/
|
||||
const app = make(Application, units)
|
||||
await app.run()
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
import {ConfigUnit, DatabaseUnit, ControllerUnit, MiddlewareUnit} from './bundle/daton_units.ts'
|
||||
|
||||
export default [
|
||||
ConfigUnit,
|
||||
DatabaseUnit,
|
||||
MiddlewareUnit,
|
||||
ControllerUnit,
|
||||
]
|
@ -0,0 +1,2 @@
|
||||
export { default as Scaffolding } from './unit/Scaffolding.ts'
|
||||
export { default as Application } from './lifecycle/Application.ts'
|
@ -1,6 +1,6 @@
|
||||
export default abstract class Cache {
|
||||
public abstract async fetch(key: string): Promise<any>;
|
||||
public abstract async put(key: string, value: any): Promise<void>;
|
||||
public abstract async put(key: string, value: string): Promise<void>;
|
||||
public abstract async has(key: string): Promise<boolean>;
|
||||
public abstract async drop(key: string): Promise<void>;
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
import {Canonical} from './Canonical.ts'
|
||||
|
||||
export class RecursiveCanonical extends Canonical<any> {
|
||||
public get(key: string): any | undefined {
|
||||
const parts = key.split('.')
|
||||
let current_value = this._items
|
||||
for ( const part of parts ) {
|
||||
current_value = current_value?.[part]
|
||||
}
|
||||
return current_value
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
import LifecycleUnit from '../../lib/src/lifecycle/Unit.ts'
|
||||
import Config from '../../lib/src/unit/Config.ts'
|
||||
import {Unit} from '../../lib/src/lifecycle/decorators.ts'
|
||||
import Database from './service/Database.ts'
|
||||
|
||||
@Unit()
|
||||
export class DatabaseUnit extends LifecycleUnit {
|
||||
constructor(
|
||||
protected config: Config,
|
||||
protected db: Database,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
|
||||
public async up() {
|
||||
const connections: { [key: string]: any } = this.config.get('db.connections')
|
||||
|
||||
for ( const conn_name in connections ) {
|
||||
if ( !connections.hasOwnProperty(conn_name) ) continue
|
||||
const config = connections[conn_name]
|
||||
|
||||
switch(config.type) {
|
||||
case 'postgres':
|
||||
await this.db.postgres(conn_name, config)
|
||||
break
|
||||
default:
|
||||
throw new TypeError(`Invalid database driver type: ${config.type}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
import {make} from "./di/src/global.ts";
|
||||
import Application from "./lib/src/lifecycle/Application.ts";
|
||||
import Scaffolding from "./lib/src/unit/Scaffolding.ts";
|
||||
import {Logging} from "./lib/src/service/logging/Logging.ts";
|
||||
import Database from "./orm/src/service/Database.ts";
|
||||
import { Model } from './orm/src/model/Model.ts'
|
||||
import {Field} from "./orm/src/model/Field.ts";
|
||||
import {QueryRow, Type} from './orm/src/db/types.ts';
|
||||
import {Builder} from "./orm/src/builder/Builder.ts";
|
||||
import ObjectResultOperator from "./orm/src/builder/type/result/ObjectResultOperator.ts";
|
||||
import {BehaviorSubject} from "./lib/src/support/BehaviorSubject.ts";
|
||||
|
||||
// TODO enum bit fields
|
||||
// TODO JSON field support
|
||||
|
||||
;(async () => {
|
||||
const scaf = make(Scaffolding)
|
||||
await scaf.up()
|
||||
|
||||
const logger = make(Logging)
|
||||
|
||||
const app = make(Application)
|
||||
await app.run()
|
||||
|
||||
const db = make(Database)
|
||||
|
||||
await db.postgres('garrettmills', {
|
||||
user: 'garrettmills',
|
||||
password: 'garrettmills',
|
||||
database: 'garrettmills',
|
||||
hostname: 'localhost',
|
||||
port: 5432,
|
||||
})
|
||||
|
||||
class User extends Model<User> {
|
||||
protected static connection = 'garrettmills'
|
||||
protected static table = 'daton_users'
|
||||
protected static key = 'user_id'
|
||||
|
||||
protected static appends: string[] = ['display_name']
|
||||
protected static masks: string[] = ['active']
|
||||
|
||||
@Field(Type.int)
|
||||
public user_id!: number
|
||||
|
||||
@Field(Type.varchar)
|
||||
public username!: string
|
||||
|
||||
@Field(Type.varchar)
|
||||
public first_name!: string
|
||||
|
||||
@Field(Type.varchar)
|
||||
public last_name!: string
|
||||
|
||||
@Field(Type.boolean)
|
||||
public active!: boolean
|
||||
|
||||
@Field(Type.timestamp)
|
||||
public updated_at!: Date
|
||||
|
||||
@Field(Type.timestamp)
|
||||
public created_at!: Date
|
||||
|
||||
get display_name(): string {
|
||||
return `${this.last_name}, ${this.first_name}`
|
||||
}
|
||||
}
|
||||
|
||||
const u = await User.find_one({ username: 'garrettmills' })
|
||||
})()
|
Loading…
Reference in new issue