-
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 #25 from ProdByGodfather/24-fix-postgresql-connect…
…ions 24 fix postgresql connections
- Loading branch information
Showing
10 changed files
with
174 additions
and
382 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,6 @@ abarorm.egg-info | |
__pycache__/ | ||
**/__pycache__/ | ||
m.py | ||
./m.py | ||
./m.py | ||
abarorm/mysql.ex.py | ||
./abarorm/mysql.ex.py |
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 |
---|---|---|
|
@@ -5,5 +5,4 @@ | |
] | ||
|
||
from .sqlite import SQLiteModel | ||
from .mysql import MySQLModel | ||
from .psql import PostgreSQLModel |
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,84 @@ | ||
from typing import Type, Optional | ||
import re | ||
|
||
class Field: | ||
def __init__(self, field_type: str, max_length: Optional[int] = None, unique: bool = False, | ||
null: bool = False, default: Optional[str] = None): | ||
self.field_type = field_type | ||
self.max_length = max_length | ||
self.unique = unique | ||
self.null = null | ||
self.default = default | ||
|
||
class CharField(Field): | ||
def __init__(self, max_length: int = 255, **kwargs): | ||
super().__init__(field_type='VARCHAR', max_length=max_length, **kwargs) # PostgreSQL uses VARCHAR for strings | ||
|
||
class IntegerField(Field): | ||
def __init__(self, **kwargs): | ||
super().__init__(field_type='INTEGER', **kwargs) | ||
|
||
class BooleanField(Field): | ||
def __init__(self, default: bool = False, **kwargs): | ||
super().__init__(field_type='BOOLEAN', default=default, **kwargs) | ||
|
||
def set_default(self): | ||
return 'TRUE' if self.default else 'FALSE' | ||
|
||
|
||
class DateTimeField(Field): | ||
def __init__(self, auto_now: bool = False, auto_now_add: Optional[bool] = None, **kwargs): | ||
super().__init__(field_type='TIMESTAMP', **kwargs) # PostgreSQL uses TIMESTAMP for DateTime fields | ||
self.auto_now = auto_now | ||
self.auto_now_add = auto_now_add | ||
|
||
class DateField(Field): | ||
def __init__(self, auto_now: bool = False, auto_now_add: Optional[bool] = None, **kwargs): | ||
super().__init__(field_type='DATE', **kwargs) # PostgreSQL uses DATE for date-only fields | ||
self.auto_now = auto_now | ||
self.auto_now_add = auto_now_add | ||
|
||
class TimeField(Field): | ||
def __init__(self, **kwargs): | ||
super().__init__(field_type='TIME', **kwargs) # PostgreSQL uses TIME for time-only fields | ||
|
||
class ForeignKey(Field): | ||
def __init__(self, to: Type['BaseModel'], on_delete: str = 'CASCADE', **kwargs): | ||
super().__init__(field_type='INTEGER', **kwargs) | ||
self.to = to # This is the related model class | ||
self.on_delete = on_delete # Specifies the behavior when the referenced row is deleted | ||
# PostgreSQL usually uses INTEGER or BIGINT for foreign key references. | ||
|
||
class FloatField(Field): | ||
def __init__(self, **kwargs): | ||
super().__init__(field_type='REAL', **kwargs) # PostgreSQL uses REAL for floating point numbers | ||
|
||
class DecimalField(Field): | ||
def __init__(self, max_digits: int, decimal_places: int, **kwargs): | ||
super().__init__(field_type='DECIMAL', **kwargs) # PostgreSQL uses DECIMAL/NUMERIC for fixed precision numbers | ||
self.max_digits = max_digits | ||
self.decimal_places = decimal_places | ||
|
||
class TextField(Field): | ||
def __init__(self, **kwargs): | ||
super().__init__(field_type='TEXT', **kwargs) # PostgreSQL uses TEXT for long strings | ||
|
||
class EmailField(CharField): | ||
EMAIL_REGEX = r'^[\w\.-]+@[\w\.-]+\.\w+$' | ||
|
||
def __init__(self, max_length: int = 255, **kwargs): | ||
super().__init__(max_length=max_length, **kwargs) | ||
|
||
def validate(self, value: str): | ||
if not re.match(self.EMAIL_REGEX, value): | ||
raise ValueError(f"Invalid email address: {value}") | ||
|
||
class URLField(CharField): | ||
URL_REGEX = r'^(https?|ftp)://[^\s/$.?#].[^\s]*$' | ||
|
||
def __init__(self, max_length: int = 2048, **kwargs): | ||
super().__init__(max_length=max_length, **kwargs) | ||
|
||
def validate(self, value: str): | ||
if not re.match(self.URL_REGEX, value): | ||
raise ValueError(f"Invalid URL: {value}") |
File renamed without changes.
Oops, something went wrong.