Expose auth repos in context; create routes commands
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-06-17 19:35:31 -05:00
parent 9796a7277e
commit 36b451c32b
14 changed files with 300 additions and 4 deletions

14
src/orm/schema/Schema.ts Normal file
View File

@@ -0,0 +1,14 @@
import {Connection} from '../connection/Connection'
import {Awaitable} from '../../util'
export abstract class Schema {
constructor(
protected readonly connection: Connection,
) { }
public abstract hasTable(name: string): Awaitable<boolean>
public abstract hasColumn(table: string, name: string): Awaitable<boolean>
public abstract hasColumns(table: string, name: string[]): Awaitable<boolean>
}

View File

@@ -0,0 +1,109 @@
import {Pipe} from '../../util'
export abstract class SchemaBuilderBase {
protected shouldDrop: 'yes'|'no'|'exists' = 'no'
protected shouldRenameTo?: string
constructor(
protected readonly name: string,
) { }
public drop(): this {
this.shouldDrop = 'yes'
return this
}
public dropIfExists(): this {
this.shouldDrop = 'exists'
return this
}
public rename(to: string): this {
this.shouldRenameTo = to
return this
}
pipe(): Pipe<this> {
return Pipe.wrap<this>(this)
}
}
export class ColumnBuilder extends SchemaBuilderBase {
}
export class IndexBuilder extends SchemaBuilderBase {
protected fields: Set<string> = new Set<string>()
protected removedFields: Set<string> = new Set<string>()
protected shouldBeUnique = false
protected shouldBePrimary = false
protected field(name: string): this {
this.fields.add(name)
return this
}
protected removeField(name: string): this {
this.removedFields.add(name)
this.fields.delete(name)
return this
}
primary(): this {
this.shouldBePrimary = true
return this
}
unique(): this {
this.shouldBeUnique = true
return this
}
}
export class TableBuilder extends SchemaBuilderBase {
protected columns: {[key: string]: ColumnBuilder} = {}
protected indexes: {[key: string]: IndexBuilder} = {}
public dropColumn(name: string): this {
this.column(name).drop()
return this
}
public renameColumn(from: string, to: string): this {
this.column(from).rename(to)
return this
}
public dropIndex(name: string): this {
this.index(name).drop()
return this
}
public renameIndex(from: string, to: string): this {
this.index(from).rename(to)
return this
}
public column(name: string) {
if ( !this.columns[name] ) {
this.columns[name] = new ColumnBuilder(name)
}
return this.columns[name]
}
public index(name: string) {
if ( !this.indexes[name] ) {
this.indexes[name] = new IndexBuilder(name)
}
return this.indexes[name]
}
}