-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add parser for schemarb #87
Conversation
import { relationshipsSchema, tableNameSchema, tableSchema } from './database' | ||
import { nodeMetaDataSchema } from './erd' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are two structure types, database and erd, so I divide structure into each file.
If this poc is good enough to merge, I am going to fix other packages where ci is failed.
relationships: relationshipsSchema, | ||
}) | ||
|
||
export type DBStructure = v.InferOutput<typeof dbStructureSchema> | ||
export type ERDStructure = v.InferOutput<typeof erdStructureSchema> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERD has a metadata such as node position and colors.
As schema name, ERDStructure
is better than DBStructure
.
Because DBStructure
doesn't seem to have any data related to erd.
How do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the parser wants to remain ignorant of information about the UI of the ER Diagrams.
I think we should leave DBStructure as it is for this PR right now, since we can consider the schema when implementing ERD!
|
||
type SupportedFormat = 'schemarb' | 'postgres' | ||
|
||
const convertToDBStructure = (data: any): DBStructure => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
convertToDBStructure
should not be implemented.
It would be better Generated parser.js
to return directly DBStructure.
So I might fix pegjs for next step if this PR is merged.
acc[table.name] = { | ||
comment: null, | ||
fields: table.fields.map((field: any) => ({ | ||
check: null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a lack of fields such as unique and check.
This is because fields parsed by pegjs do not contain these data.
This is also issue to solve by editing pegjs.
frontend/packages/db-structure/src/parser/schemarb/parser.pegjs
Outdated
Show resolved
Hide resolved
version = "version" | ||
do = "do" | ||
end = "end" | ||
lambda_function "lambda function" = "=>" / "->" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Ruby, ->
is used as a shorthand for lambda
, while =>
is typically used to define key-value pairs in a Hash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was fixed in 8d86366, but =>
might still appear, so handling =>
itself might still be necessary. That said, we could also address it if and when any issues arise. Let’s proceed with this for now!
…compiler options from tsconfig.json
@@ -7,14 +7,18 @@ | |||
"lint:biome": "biome check .", | |||
"lint:tsc": "tsc --noEmit", | |||
"fmt": "conc -c auto pnpm:fmt:*", | |||
"fmt:biome": "biome check --write --unsafe ." | |||
"fmt:biome": "biome check --write --unsafe .", | |||
"test": "vitest" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Fixed:
Next work:
|
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding it! 😄
I refereed to https://github.com/holistics/dbml/blob/master/LICENSE
sample (MIT not Apache2.0): https://github.com/antlr/grammars-v4/blob/master/sql/postgresql/PostgreSQLLexer.g4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀🚀🚀
Summary
This is proof of concept for parsing schema.rb to DBStructure.
Related Issue
N/A
Changes
npx peggy parser.pegjs
Testing
Other Information