Skip to content

Commit

Permalink
Update HISTORY and other docs for 0.0.6 release
Browse files Browse the repository at this point in the history
  • Loading branch information
jzmiller1 committed Aug 17, 2024
1 parent 9b16341 commit 90dfa1e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
8 changes: 8 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## v0.0.6 (2024-08-16)

* Enhanced the `Database` class to allow accessing schema objects via dot notation (e.g., `db.schema_name.table_name`)
* Added the `.columns` attribute to the `Table` class to extract column names, supporting both simple and complex table definitions, including those with constraints
* `.columns` properly handles inherited columns for tables using the `INHERITS` clause
* Updated the `Database` class to enforce loading schemas before any dependent items, raising errors when schemas are not loaded in the correct order
* Updated GitHub Actions workflows to support Python 3.12

## v0.0.5 (2023-06-12)

* add ability to create View and Trigger
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ postnormalism is Not an Object Relational Mapper (NORM) it is a lightweight and

## Features

- Define schemas, tables, views, triggers and functions using Python dataclasses
- Manage the creation of schemas, tables, views, triggers and functions using Python dataclasses
- Create database items with comments
- Group related database items and create them within a single transaction
- Create a Database object that allows loading database items in a specified load order and managing database extensions
- Access database objects through the Database class using dot notation, with schema-based grouping (e.g., `db.schema_name.table_name`).
- exists mode for loading database items with IF NOT EXISTS and OR REPLACE
- SQL Migration Loader

Expand Down Expand Up @@ -83,6 +84,30 @@ description varchar(240)
"""

Material = Table(create=create_table_sql)

# Access the columns
print(Material.columns) # Outputs: ['id', 'name', 'description']

# Define a parent table
create_parent_table_sql = """
CREATE TABLE parent_table (
id uuid PRIMARY KEY,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
"""

# Define a child table that inherits from the parent table
create_child_table_sql = """
CREATE TABLE child_table (
name varchar(120)
) INHERITS (parent_table);
"""

ParentTable = Table(create=create_parent_table_sql)
ChildTable = Table(create=create_child_table_sql)

# The child table's columns will include those from the parent table
print(ChildTable.columns) # Outputs: ['id', 'created_at', 'name']
```

### Define a Postgresql Function
Expand Down Expand Up @@ -144,6 +169,15 @@ Calling Database.create with exists=True inserts IF NOT EXISTS or OR REPLACE int
universe.create(cursor, exists=True)
```

### Accessing Schema Objects via Dot Notation
You can now access tables, views, and other schema objects directly through the `Database` instance using dot notation:

```python
# Assuming you have already defined a schema and table
print(db.schema_name.table_name.name) # Outputs the table name
print(db.schema_name.table_name.columns) # Outputs the list of columns in the table
```

### Doing migrations
Update your `DatabaseItem`s and write your SQL migration transaction. If you create your Database instance with
a `migrations_folder` they will run during the create call. Migration files should ideally be prefixed with a
Expand Down
22 changes: 12 additions & 10 deletions STRUCTURE
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@
| |-- workflows/
| | |-- release.yml
| | |-- test.yml
|-- .gitignore
|-- HISTORY.md
|-- LICENSE
|-- README.md
|-- STRUCTURE
|-- postnormalism/
| |-- VERSION
| |-- __init__.py
| |-- core.py
| |-- schema/
| | |-- __init__.py
| | |-- database.py
Expand All @@ -21,14 +13,24 @@
| | |-- table.py
| | |-- trigger.py
| | |-- view.py
| |-- __init__.py
| |-- core.py
| |-- utils.py
|-- pyproject.toml
|-- tests/
| |-- __init__.py
| |-- items/
| | |-- __init__.py
| | |-- test_function.py
| | |-- test_schema.py
| | |-- test_table.py
| | |-- test_trigger.py
| | |-- test_view.py
| |-- __init__.py
| |-- test_core.py
| |-- test_database.py
|-- .gitignore
|-- .gptignore
|-- HISTORY.md
|-- LICENSE
|-- pyproject.toml
|-- README.md
|-- STRUCTURE
1 change: 0 additions & 1 deletion postnormalism/VERSION

This file was deleted.

0 comments on commit 90dfa1e

Please sign in to comment.