EnORM—EnDATA Object Relational Mapper.
Project description
EnORM
EnORM—EnDATA Object Relational Mapper.
- EnORM
- Example Usage
- Documentation
- API Reference
const .fkey.CASCADE
[source]class .column.Column(type_, length=None, rel=None, *, primary_key=False, default=None, nullable=True)
[source]class .types.Date
[source]class .types.DateTime
[source]class .db_engine.DBEngine(conn_str)
[source]class .db_session.DBSession(engine)
[source]class .fkey.ForeignKey(foreign_model, *, reverse_name, on_delete, on_update)
[source]class .model.Model(**attrs)
[source]class .types.Float
[source]class .types.Integer
[source]class .types.Serial
[source]class .types.String
[source]class .types.Time
[source]func agg(field, name_in_sql)
->.column.BaseColumn
[source]func count(field)
->.column.BaseColumn
[source]func sum_(field)
->.column.BaseColumn
[source]func avg(field)
->.column.BaseColumn
[source]func min_(field)
->.column.BaseColumn
[source]func max_(field)
->.column.BaseColumn
[source]func char_length(c)
->.column.Scalar
[source]func concat(*parts)
->str
[source]func current_date()
->.column.Scalar
[source]func current_time(precision=None)
->.column.Scalar
[source]func current_timestamp(precision=None)
->.column.Scalar
[source]func current_user()
->.column.Scalar
[source]func local_time(precision=None)
->.column.Scalar
[source]func local_timestamp()
->.column.Scalar
[source]func now()
->.column.Scalar
[source]func random()
->.column.Scalar
[source]func session_user()
->.column.Scalar
[source]func user()
->.column.Scalar
[source]
- Tutorial
- API Reference
Example Usage
from EnORM import CASCADE, Column, DBEngine, DBSession, Float, ForeignKey, Integer, Model, Serial, String
class Company(Model):
__table__ = "companies"
id = Column(Serial, primary_key=True)
name = Column(String, nullable=False)
country = Column(String, 40)
class Employee(Model):
id = Column(Serial, primary_key=True)
full_name = Column(String, 100, nullable=False)
salary = Column(Float)
age = Column(Integer)
role = Column(String, 20, default="entry")
company_id = Column(Serial, None, ForeignKey(Company, reverse_name="employees", on_delete=CASCADE))
eng = DBEngine("postgresql://user:secret@localhost:5432/my_db")
with DBSession(eng) as session:
the_company = session.query(Company).filter(Company.country == "United Kingdom").first()
new_employee = Employee(full_name="Nima Bavari Goudarzi", salary=64320.00, role="engineer", company_id=the_company.id)
session.add(new_employee)
sharks = session.query(Employee, Employee.full_name, Employee.company_id).filter(Employee.salary > 90000.00).all()
Documentation
API Reference
Reference for the EnORM public API.
const .fkey.CASCADE
[source]
String literal "cascade".
class .column.Column(type_, length=None, rel=None, *, primary_key=False, default=None, nullable=True)
[source]
Abstraction of a real table column in a database.
Parameters
type_ :
typing.Type
The type of the column as represented in SQL.
length :
int | None
(defaultNone
)Max length of the value. Provided only when the type of the column is
.types.String
.rel :
.fkey.ForeignKey | None
(defaultNone
)Marker of a relationship. Provided only when a foreign relation exists.
primary_key :
bool
(defaultFalse
)Whether or not the column is a primary key. Keyword-only.
default :
typing.Any
(defaultNone
)Default value for cells of the column to take. Keyword-only.
nullable :
bool
(defaultTrue
)Whether or not the cells of the column are nullable. Keyword-only.
Attributes
model :
typing.Type
Relational model that the column belongs to.
variable_name :
str
Name with which the column is defined.
view_name :
str
Name of the SQL table that the column belongs to.
class .types.Date
[source]
ORM representation of datetime.date
objects.
class .types.DateTime
[source]
ORM representation of datetime.datetime
objects.
class .db_engine.DBEngine(conn_str)
[source]
Connection adapter for the .db_session.DBSession
object.
Parameters
conn_str :
str
Database resource location, along with auth params.
Attributes
conn :
pyodbc.Connection
DB API connection object.
cursor :
pyodbc.Cursor
DB API cursor object.
class .db_session.DBSession(engine)
[source]
Singleton DB session to access the database across all uses.
Parameters
engine :
.db_engine.AbstractEngine
DB engine that the session uses.
Attributes
engine :
.db_engine.AbstractEngine
DB engine that the session uses.
queue :
list
List of newly created instances of DB objects not yet persisted.
accumulator :
list
List of ORM queries not yet executed.
Methods
query(*fields) ->
.query.Query
Starts a query and returns the query object.
add(obj) ->
None
Adds a new record to the DB session.
save() ->
None
Persists all started queries.
commit_adds() ->
None
Persists all added records on the DB session.
class .fkey.ForeignKey(foreign_model, *, reverse_name, on_delete, on_update)
[source]
Representer of foreign key relations.
Parameters
foreign_model :
typing.Type
MappedClass
that represents a foreign model.reverse_name :
str
Relation name on the related class tied to this class. Keyword-only.
on_delete :
str | None
(defaultNone
)Whether to delete cascade style or not. Keyword-only.
on_update :
str | None
(defaultNone
)Whether to update cascade style or not. Keyword-only.
class .model.Model(**attrs)
[source]
Abstract representer of an ORM database model in Python.
Parameters
attrs :
typing.Any
Initialization attributes.
Attributes
sql :
str
SQL statement for new object creation.
Methods
label(alias) ->
.column.Label
Returns the ORM representation for SQL table aliasing.
class .types.Float
[source]
ORM representation of float
objects.
class .types.Integer
[source]
ORM representation of int
objects.
class .types.Serial
[source]
ORM representation of serial types in SQL variants.
Parameters
val :
int
Underlying integer value.
Attributes
val :
int
Underlying integer value.
class .types.String
[source]
ORM representation of str
objects.
class .types.Time
[source]
ORM representation of datetime.time
objects.
func agg(field, name_in_sql)
-> .column.BaseColumn
[source]
Describes the basis for all aggregate functions.
Parameters
field :
.column.BaseColumn
Argument.
name_in_sql :
str
Name of the function in SQL.
func count(field)
-> .column.BaseColumn
[source]
Describes the SQL aggregate function COUNT
.
func sum_(field)
-> .column.BaseColumn
[source]
Describes the SQL aggregate function SUM
.
func avg(field)
-> .column.BaseColumn
[source]
Describes the SQL aggregate function AVG
.
func min_(field)
-> .column.BaseColumn
[source]
Describes the SQL aggregate function MIN
.
func max_(field)
-> .column.BaseColumn
[source]
Describes the SQL aggregate function MAX
.
func char_length(c)
-> .column.Scalar
[source]
Describes the SQL function CHAR_LENGTH
.
Parameters
c :
.column.BaseColumn | str
Generic column or its string value.
func concat(*parts)
-> str
[source]
Concatenates multiple strings into one.
Parameters
parts : list of
str
Separate parts.
func current_date()
-> .column.Scalar
[source]
Describes the SQL function CURRENT_DATE
.
func current_time(precision=None)
-> .column.Scalar
[source]
Describes the SQL function CURRENT_TIME
.
Parameters
precision :
int | None
(defaultNone
)Number of significant decimal digits.
func current_timestamp(precision=None)
-> .column.Scalar
[source]
Describes the SQL function CURRENT_TIMESTAMP
.
Parameters
precision :
int | None
(defaultNone
)Number of significant decimal digits.
func current_user()
-> .column.Scalar
[source]
Describes the SQL function CURRENT_USER
.
func local_time(precision=None)
-> .column.Scalar
[source]
Describes the SQL function LOCALTIME
.
Parameters
precision :
int | None
(defaultNone
)Number of significant decimal digits.
func local_timestamp()
-> .column.Scalar
[source]
Describes the SQL function LOCALTIMESTAMP
.
func now()
-> .column.Scalar
[source]
Describes the SQL function NOW
.
func random()
-> .column.Scalar
[source]
Describes the SQL function RANDOM
.
func session_user()
-> .column.Scalar
[source]
Describes the SQL function SESSION_USER
.
func user()
-> .column.Scalar
[source]
Describes the SQL function USER
.
Tutorial
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.