-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from liam-hq/add_prism_parser
feat: add prism parser
- Loading branch information
Showing
14 changed files
with
1,415 additions
and
1,015 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,4 +1,3 @@ | ||
export { parse } from './parser/index.js' | ||
export { | ||
type DBStructure, | ||
type Table, | ||
|
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 { parse } from './parser/index.js' |
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
170 changes: 170 additions & 0 deletions
170
frontend/packages/db-structure/src/parser/schemarb-prism/index.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 |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import type { Table } from 'src/schema' | ||
import { aColumn, aDBStructure, aTable } from 'src/schema/factories' | ||
import { describe, expect, it } from 'vitest' | ||
import { processor } from '.' | ||
|
||
describe(processor, () => { | ||
describe('should parse create_table correctry', () => { | ||
const userTable = (override?: Partial<Table>) => | ||
aDBStructure({ | ||
tables: { | ||
users: aTable({ | ||
name: 'users', | ||
columns: { | ||
id: aColumn({ | ||
name: 'id', | ||
type: 'bigserial', | ||
notNull: true, | ||
primary: true, | ||
unique: true, | ||
}), | ||
...override?.columns, | ||
}, | ||
}), | ||
}, | ||
}) | ||
|
||
it('not null', async () => { | ||
const result = await processor(/* Ruby */ ` | ||
create_table "users" do |t| | ||
t.string "name", null: false | ||
end | ||
`) | ||
|
||
const expected = userTable({ | ||
columns: { | ||
name: aColumn({ | ||
name: 'name', | ||
type: 'string', | ||
notNull: true, | ||
}), | ||
}, | ||
}) | ||
|
||
expect(result).toEqual(expected) | ||
}) | ||
|
||
it('nullable', async () => { | ||
const result = await processor(/* Ruby */ ` | ||
create_table "users" do |t| | ||
t.string "name", null: true | ||
end | ||
`) | ||
|
||
const expected = userTable({ | ||
columns: { | ||
name: aColumn({ | ||
name: 'name', | ||
type: 'string', | ||
notNull: false, | ||
}), | ||
}, | ||
}) | ||
|
||
expect(result).toEqual(expected) | ||
}) | ||
|
||
it('defalt value as string', async () => { | ||
const result = await processor(/* Ruby */ ` | ||
create_table "users" do |t| | ||
t.string "name", default: "new user", null: true | ||
end | ||
`) | ||
|
||
const expected = userTable({ | ||
columns: { | ||
name: aColumn({ | ||
name: 'name', | ||
type: 'string', | ||
notNull: false, | ||
default: 'new user', | ||
}), | ||
}, | ||
}) | ||
|
||
expect(result).toEqual(expected) | ||
}) | ||
|
||
it('defalt value as integer', async () => { | ||
const result = await processor(/* Ruby */ ` | ||
create_table "users" do |t| | ||
t.integer "age", default: 30, null: true | ||
end | ||
`) | ||
|
||
const expected = userTable({ | ||
columns: { | ||
age: aColumn({ | ||
name: 'age', | ||
type: 'integer', | ||
notNull: false, | ||
default: 30, | ||
}), | ||
}, | ||
}) | ||
|
||
expect(result).toEqual(expected) | ||
}) | ||
|
||
it('defalt value as boolean', async () => { | ||
const result = await processor(/* Ruby */ ` | ||
create_table "users" do |t| | ||
t.boolean "active", default: true, null: true | ||
end | ||
`) | ||
|
||
const expected = userTable({ | ||
columns: { | ||
active: aColumn({ | ||
name: 'active', | ||
type: 'boolean', | ||
notNull: false, | ||
default: true, | ||
}), | ||
}, | ||
}) | ||
|
||
expect(result).toEqual(expected) | ||
}) | ||
|
||
it('primary key as args', async () => { | ||
const result = await processor(/* Ruby */ ` | ||
create_table "users", id: :bigint | ||
`) | ||
|
||
const expected = userTable({ | ||
columns: { | ||
id: aColumn({ | ||
name: 'id', | ||
type: 'bigint', | ||
notNull: true, | ||
primary: true, | ||
unique: true, | ||
}), | ||
}, | ||
}) | ||
|
||
expect(result).toEqual(expected) | ||
}) | ||
|
||
it('unique', async () => { | ||
const result = await processor(/* Ruby */ ` | ||
create_table "users" do |t| | ||
t.string "name", unique: true | ||
end | ||
`) | ||
|
||
const expected = userTable({ | ||
columns: { | ||
name: aColumn({ | ||
name: 'name', | ||
type: 'string', | ||
unique: true, | ||
}), | ||
}, | ||
}) | ||
|
||
expect(result).toEqual(expected) | ||
}) | ||
}) | ||
}) |
1 change: 1 addition & 0 deletions
1
frontend/packages/db-structure/src/parser/schemarb-prism/index.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { processor } from './parser' |
Oops, something went wrong.