-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ schema: support drizzle introspection
- Loading branch information
1 parent
89df194
commit c24caba
Showing
5 changed files
with
155 additions
and
0 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
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,28 @@ | ||
import { _ITable, _ISelection, _IIndex, _IDb, _ISchema } from '../../interfaces-private'; | ||
import { Schema } from '../../interfaces'; | ||
import { Types } from '../../datatypes'; | ||
import { ReadOnlyTable } from '../readonly-table'; | ||
|
||
export class PgEnumTable extends ReadOnlyTable implements _ITable { | ||
|
||
_schema: Schema = { | ||
name: 'pg_enum', | ||
fields: [ | ||
{ name: 'oid', type: Types.integer } | ||
, { name: 'enumtypid', type: Types.integer } | ||
, { name: 'enumsortorder', type: Types.integer } | ||
, { name: 'enumlabel', type: Types.text() } | ||
] | ||
}; | ||
|
||
entropy(): number { | ||
return 0; | ||
} | ||
|
||
*enumerate() { | ||
} | ||
|
||
hasItem(value: any): boolean { | ||
return false; | ||
} | ||
} |
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,35 @@ | ||
import { _ITable, _ISelection, _IIndex, _IDb, _ISchema } from '../../interfaces-private'; | ||
import { Schema } from '../../interfaces'; | ||
import { Types } from '../../datatypes'; | ||
import { ReadOnlyTable } from '../readonly-table'; | ||
|
||
export class PgSequencesTable extends ReadOnlyTable implements _ITable { | ||
|
||
_schema: Schema = { | ||
name: 'pg_sequences', | ||
fields: [ | ||
{ name: 'schemaname', type: Types.text() } | ||
, { name: 'sequencename', type: Types.text() } | ||
, { name: 'sequenceowner', type: Types.integer } | ||
, { name: 'data_type', type: Types.text() } | ||
, { name: 'start_value', type: Types.integer } | ||
, { name: 'min_value', type: Types.integer } | ||
, { name: 'max_value', type: Types.integer } | ||
, { name: 'increment_by', type: Types.integer } | ||
, { name: 'cycle', type: Types.bool } | ||
, { name: 'cache_size', type: Types.integer } | ||
, { name: 'last_value', type: Types.integer } | ||
] | ||
}; | ||
|
||
entropy(): number { | ||
return 0; | ||
} | ||
|
||
*enumerate() { | ||
} | ||
|
||
hasItem(value: any): boolean { | ||
return false; | ||
} | ||
} |
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,34 @@ | ||
import { _ITable, _ISelection, _IIndex, _IDb, _ISchema } from '../../interfaces-private'; | ||
import { Schema } from '../../interfaces'; | ||
import { Types } from '../../datatypes'; | ||
import { ReadOnlyTable } from '../readonly-table'; | ||
|
||
export class PgUserTable extends ReadOnlyTable implements _ITable { | ||
|
||
_schema: Schema = { | ||
name: 'pg_user', | ||
fields: [ | ||
{ name: 'usename', type: Types.text() } | ||
, { name: 'usesysid', type: Types.integer } | ||
, { name: 'usecreatedb', type: Types.bool } | ||
, { name: 'usesuper', type: Types.bool } | ||
, { name: 'usecatupd', type: Types.bool } | ||
, { name: 'userepl', type: Types.bool } | ||
, { name: 'usebypassrls', type: Types.bool } | ||
, { name: 'passwd', type: Types.text() } | ||
, { name: 'valuntil', type: Types.timestamptz() } | ||
, { name: 'useconfig', type: Types.jsonb } | ||
] | ||
}; | ||
|
||
entropy(): number { | ||
return 0; | ||
} | ||
|
||
*enumerate() { | ||
} | ||
|
||
hasItem(value: any): boolean { | ||
return false; | ||
} | ||
} |
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,52 @@ | ||
import { describe, it, beforeEach, expect } from 'bun:test'; | ||
|
||
import { newDb } from '../db'; | ||
|
||
import { _IDb } from '../interfaces-private'; | ||
|
||
describe('drizzle - requests', () => { | ||
|
||
let db: _IDb; | ||
let many: (str: string) => any[]; | ||
let none: (str: string) => void; | ||
beforeEach(() => { | ||
db = newDb({ | ||
autoCreateForeignKeyIndices: true, | ||
}) as _IDb; | ||
many = db.public.many.bind(db.public); | ||
none = db.public.none.bind(db.public); | ||
}); | ||
|
||
function simpleDb() { | ||
db.public.none('create table data(id text primary key, data jsonb, num integer, var varchar(10))'); | ||
} | ||
|
||
it('can select pg_user', () => { | ||
simpleDb(); | ||
many(`select s.nspname as table_schema | ||
from pg_catalog.pg_namespace s | ||
join pg_catalog.pg_user u on u.usesysid = s.nspowner | ||
where nspname not in ('information_schema', 'pg_catalog', 'public') | ||
and nspname not like 'pg_toast%' | ||
and nspname not like 'pg_temp_%' | ||
order by table_schema`); | ||
}); | ||
|
||
it('can select pg_sequences', () => { | ||
simpleDb(); | ||
many(`select schemaname, sequencename, start_value, min_value, max_value, increment_by, cycle, cache_size from pg_sequences as seq WHERE schemaname = 'public'`); | ||
}); | ||
|
||
it('can select pg_enum', () => { | ||
simpleDb(); | ||
many(`select n.nspname as enum_schema, | ||
t.typname as enum_name, | ||
e.enumlabel as enum_value, | ||
e.enumsortorder as sort_order | ||
from pg_type t | ||
join pg_enum e on t.oid = e.enumtypid | ||
join pg_catalog.pg_namespace n ON n.oid = t.typnamespace | ||
where n.nspname = 'public' | ||
order by enum_schema, enum_name, sort_order`); | ||
}); | ||
}); |