Skip to content

Commit

Permalink
add documentation about famix sql
Browse files Browse the repository at this point in the history
  • Loading branch information
badetitou committed Oct 26, 2023
1 parent 04fc912 commit 8c0b3f7
Show file tree
Hide file tree
Showing 26 changed files with 147 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cSpell.words": [
"Famix",
"Pharo"
]
}
127 changes: 127 additions & 0 deletions moose-wiki/Users/famix-sql/getting-started-with-famixsql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
layout: page
author: Benoit Verhaeghe
background: '/img/bg-wiki.jpg'
title: 'Getting started with FamixSQL'
---

This page is a guide on how to use Moose to analyze your relational database using FamixSQL.

## What is FamixSQL?

FamixSQL is a meta-model and a Famix importer that can be use to create a model of a database.
The FamixSQL importer relies on [ODBC](https://en.wikipedia.org/wiki/Open_Database_Connectivity) to create the model, thus, it is compatible with a wide range of RDBMS such as Oracle, PostgreSQL, and MSSQL.

The goal of FamixSQL is to give you tools to better understand your database, the dependencies between the tables, and the *health* of your schema.
To do so, it relies *critics* analysis using a first set of rules that one can extend with its specific needs.

## Installation

### Load FamixSQL

To install FamixSQL, you'll need a Moose10 or Moose11 image (see the [install Moose page](/moose-wiki/Beginners/InstallMoose)).

In the Moose image, in a playground (`Ctrl+O`, `Ctrl+W`), perform:

```st
Metacello new
baseline: 'FamixSQL';
repository: 'github://moosetechnology/FamixSQL:main/src';
load.
```

This command will load the FamixSQL project as well as all its Pharo dependencies.

### Model Loading

To load a model from an ODBC connection, you first have to create the ODBC connection in your computer.
You can find plenty of tutorial on this subject on internet: [for Window](https://learn.microsoft.com/en-us/sql/integration-services/import-export-data/connect-to-an-odbc-data-source-sql-server-import-and-export-wizard?view=sql-server-ver16).

Once you have set up the odbc connection, you will be able to use it through Moose.
To do so, again in a playground, perform:

```st
connection := ODBCConnection new.
connection dsn: '<dsn name>'.
connection uid: '<username>'. "Username"
connection pwd: '<password>'. "Password"
connection connect.
```

> Replace value between `<>` by yours
This step create a connection object that will be use by the Famix importer.
You can now import perform the import by executing **in the same playground** the following script:

```st
importer := FamixSQLODBCImporter new.
"importer schema: '<my schema>'."
importer model: FamixSQLModel new.
importer source: connection.
model := importer import.
"Install in the Moose system"
model name: 'myDatabase'.
model installWithCache: false.
```

> Import step can take time. Be patient.
### Analyse the database

Once you have loaded the model, it is possible to analyze the database.
We describe here how to use the preconfigured analysis made using [Moose Critics]({% post_url 2022-08-08-moosecritics %}).

First, open the [Models Browser](/moose-wiki/Users/moose-ide/browsers#models-browser).
It shows a list of all the model loading in your Moose environment.
You should see the model `myDatabase` loaded in the previous step.

Then, open the Critics Browser.
In the critics browser, you will be able to load the predefined critics rules.
To do so, click on the `Import rules` button, then search in the file browser the file `db-critics.ston` that should be positioned near the FamixSQL git repository cloned in the first step. **By default,** it will be located under `<your home directory>/Pharo/images/<your image name>/pharo-local/iceberg/moosetechnology/FamixSQL/critics`.
You should see the list of rules in the middle panel of the Critics Browser.

You can now select your model in the Models Browser, and click on the `Propagate` button that will send your model to the Critics Browser.
In the Critics Browser, you should see your model entities in the left panel.

Finally, click on the `Run` button of the Critics Browser browser.
It will compute the rules and present the list of entities that raised an issue.
By *double-cliking* on an entity, you will be able to browse the violation using the [Moose Inspector](/moose-wiki/Users/moose-ide/browsers#moose-inspector)

## Additional analysis

Based on our work, we also built some additional analysis.
Some might already be integrated in the full Moose environment, and others are specific to this module.
Thus, we list some of our analysis that might help you analyzing your database.

### Visualization of the tables with their link

A Roassal3 visualization of the tables and their link is also available in this package and can be opened by executing the following script:

```st
tables := ((model allWithType: FamixSQLTable) first: 10) asMooseSpecializedGroup.
(SQLRSTableGroupBuilder new
sourceGroup: tables;
collapseAll;
build;
canvas) open.
```

### Table without primary key

To retrieve all tables without a primary key using a playground, you can perform the following script:

```st
(model allWithType: FamixSQLTable) select: [ :table | table columns noneSatisfy: #isPrimaryKeyColumn ]
```

## A bit more

### Raise an issue

If you have any trouble using FamixSQL, do not hesitate to [raise an issue](https://github.com/moosetechnology/FamixSQL/issues) or to contribute with a [pull request](https://github.com/moosetechnology/FamixSQL/pulls).

### Acknowledgement

Many thanks to Julien Deplanque who made the [first version of this work](https://github.com/juliendelplanque/FAMIXNGSQL).
File renamed without changes.
File renamed without changes
File renamed without changes.
8 changes: 4 additions & 4 deletions moose-wiki/Users/typicalQueries/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ We present how to perform the queries in a playground or with the visual tool pr

#### Class with a specific name

Using the [*Queries Browser*]({{ site.baseurl }}/moose-wiki/Users/Moose%20IDE/browsers#queries-browser): first, we request all the classes of a model.
Using the [*Queries Browser*]({{ site.baseurl }}/moose-wiki/Users/moose-ide/browsers#queries-browser): first, we request all the classes of a model.

![Query All Classes](./img/class-with-name-getClasses.png){: .img-fill .img-center }

Expand Down Expand Up @@ -65,7 +65,7 @@ withSuffix := classes select: [ :class | class name endsWith: #'MySuffix' ]
[God classes](https://en.wikipedia.org/wiki/God_object) are classes that *knows too much* or *does too much*.
One way to find god classes is to count the number of lines or the number of methods of a class.

Using the [*Queries Browser*]({{ site.baseurl }}/moose-wiki/Users/Moose%20IDE/browsers#queries-browser), one can use the Numeric Query on the classes of a model.
Using the [*Queries Browser*]({{ site.baseurl }}/moose-wiki/Users/moose-ide/browsers#queries-browser), one can use the Numeric Query on the classes of a model.

![Numeric Query](./img/query-properties-god-classes.png){: .img-fill .img-center }

Expand Down Expand Up @@ -141,7 +141,7 @@ It also includes the methods and attributes of each class.

![Moose 9 version](https://img.shields.io/badge/Moose-9-%23aac9ff.svg){: .no-lightense }

The easiest way to visualize a class hierarchy is to use the [*UML browser*]({{ site.baseurl }}/moose-wiki/Users/Moose%20IDE/browsers#uml-browser).
The easiest way to visualize a class hierarchy is to use the [*UML browser*]({{ site.baseurl }}/moose-wiki/Users/moose-ide/browsers#uml-browser).

It is also possible to script one UML visualisation of Roassal.

Expand Down Expand Up @@ -199,4 +199,4 @@ builder canvas @ RSHierarchyPacker.
builder canvas
```

A better solution to explore a meta-model is to use the [*Meta Browser*]({{ site.baseurl }}/moose-wiki/Users/Moose%20IDE/browsers#meta-browser) that provides a detailed view on every important aspects of a meta-model.
A better solution to explore a meta-model is to use the [*Meta Browser*]({{ site.baseurl }}/moose-wiki/Users/moose-ide/browsers#meta-browser) that provides a detailed view on every important aspects of a meta-model.
12 changes: 10 additions & 2 deletions moose-wiki/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,25 @@ After installing and running Moose, one typically:

### Loading a model

You can find different

#### Famix Java

A popular meta-model is the Java meta-model:

- [Famix Maker](https://github.com/moosetechnology/Moose-Easy)
![External documentation](https://img.shields.io/badge/-External%20Documentation-blue){: .no-lightense}
- [Analyse Java Project](https://fuhrmanator.github.io/2019/07/29/AnalyzingJavaWithMoose.html)
![External documentation](https://img.shields.io/badge/-External%20Documentation-blue){: .no-lightense}

#### Famix SQL

- [Getting started with FamixSQL](./Users/famix-sql/getting-started-with-famixsql)

You may also use models for other programming languages (see also the [Parsers](#Parsers) section):

- [Importing and exporting models](Users/ImportingAndExportingModels)
- [Moose supported file format](./Users/fileFormat)
- [Moose supported file format](./Users/file-format)

#### Famix AST (FAST)

Expand All @@ -63,7 +71,7 @@ You may also use models for other programming languages (see also the [Parsers](
Moose IDE is a group of tools that one can use to explore a model.
In this section, we group the documentation for each tool.

- [Moose IDE Browsers](Users/Moose%20IDE/browsers)
- [Moose IDE Browsers](Users/moose-ide/browsers)

### Visualizing a model

Expand Down

0 comments on commit 8c0b3f7

Please sign in to comment.