marguerite

Marguerite provides a declarative, consistent accessor to data layer.

https://github.com/teitei-tk/marguerite

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (8.1%) to scientific vocabulary

Keywords

architecture dispatcher marguerite sqlalchemy

Keywords from Contributors

interactive serializer cycles packaging network-simulation shellcodes hacking autograding observability genomics
Last synced: 6 months ago · JSON representation

Repository

Marguerite provides a declarative, consistent accessor to data layer.

Basic Info
  • Host: GitHub
  • Owner: teitei-tk
  • License: apache-2.0
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 32.2 KB
Statistics
  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • Open Issues: 2
  • Releases: 0
Topics
architecture dispatcher marguerite sqlalchemy
Created about 9 years ago · Last pushed almost 3 years ago
Metadata Files
Readme License

README.md

Marguerite

Marguerite provides a declarative, consistent accessor to data layer.


Build Status PyPI version

Dependencies

  • Python 2.7 or later
  • Werkzeug 0.12.7 or later

Installation

bash $ pip install Marguerite

Usage

Example

Install requests as an example.

bash $ pip install requests

  1. define data layer accessor, and writen access structure ```python from marguerite import AbstractStructure, AbstractAccessor, Order from marguerite.accessors import bind

class Accessor(AbstractAccessor): def prepare(self, name, value): order = self.structure.get_order(name) return bind(order, value)

def create(self, name, value):
    order = self.prepare(name, value)
    return requests.post(order).json()

def get(self, name, value={}):
    order = self.prepare(name, value)
    return requests.get(order).json()

class UserStructure(AbstractStructure): accessor = Accessor

orders = Order(
    user = "https://example.com/users/:id",
    create = "https://example.com/users/:id?=username=:username"
)

```

  1. get data layer accessor object ```python from marguerite import Marguerite

marguerite = Marguerite() accessor = marguerite.get_accessor("path.to.UserStructure") ```

  1. fetch data ```python # execute get logic result = accessor.get("user", { "id": 1 }) print(result) # {"id": 1, "username": "john"...}

execute post logic

result = accessor.create("create", { "id": 2, "username": "marguerite" }) print(result) # {"status": "success", {"result": {"id": 2, "username": "marguerite"...}}} ```

SQLAlchemy

bash $ pip install SQLAlchemy PyMySQL

  1. create database mysql mysql> create database marguerite; Query OK, 1 row affected (0.00 sec)

  2. define database structure ```python from marguerite import Order from marguerite.accessors.sql import SQLAlchemyAccessor from marguerite.structures.sql import SQLAlchemyStructure

class User(SQLAlchemyStructure): struct = { "id": int(), "name": str(), "email": str(), }

orders = Order(
    create_table = """
        CREATE TABLE IF NOT EXISTS __table__(
          id int(11) unsigned NOT NULL AUTO_INCREMENT,
          name varchar(255) NOT NULL DEFAULT '',
          PRIMARY KEY (id)
        ) ENGINE=InnoDB CHARSET=utf8;
    """,

    drop_table = """
        DROP TABLE IF EXISTS __table__
    """,

    insert = """
        INSERT INTO
            __table__(name)
        VALUES
            (:name)
    """,

    select = """
        SELECT
            *
        FROM
            __table__
        WHERE
            id = :id
    """,

    find = """
        SELECT
            *
        FROM
            __table__
        WHERE
            id in (:id1, :id2)
    """
)

```

  1. get database accessor object ```python from marguerite import Marguerite

engine = create_engine("mysql+pymysql://root:@localhost/marguerite")

marguerite = Marguerite(engine) accessor = marguerite.get_accessor("path.to.User") ```

  1. create table python accessor.execute("create_table")

  2. check also mysql mysql> use marguerite Database changed mysql> show tables; +----------------------+ | Tables_in_marguerite | +----------------------+ | user | +----------------------+

  3. fetch data ```python

    insert record at user table

    accessor.execute("insert", {"name": "john"})

get record

row = accessor.get("select", { "id": 1 }) print(row) # {"id": 1, "name": "john", "email": ""}

find records

rows = accessor.find("find", { "id1": 1, "id2": 2 }) print(rows) # [{"id": 1, "name": "john", "email": ""}] ```

LICENSE

Apache License 2.0

Owner

  • Name: Yoshikatsu Higa
  • Login: teitei-tk
  • Kind: user
  • Location: Tokyo, Japan

GitHub Events

Total
Last Year

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 18
  • Total Committers: 2
  • Avg Commits per committer: 9.0
  • Development Distribution Score (DDS): 0.056
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
teitei-tk t****k@g****m 17
dependabot[bot] 4****] 1

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 8
  • Average time to close issues: N/A
  • Average time to close pull requests: 10 days
  • Total issue authors: 0
  • Total pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.13
  • Merged pull requests: 5
  • Bot issues: 0
  • Bot pull requests: 4
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • dependabot[bot] (4)
  • teitei-tk (4)
Top Labels
Issue Labels
Pull Request Labels
dependencies (4)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 8 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 4
  • Total maintainers: 1
pypi.org: marguerite

Marguerite provides a declarative, consistent accessor to data layer.

  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 8 Last month
Rankings
Dependent packages count: 10.0%
Dependent repos count: 21.7%
Forks count: 22.6%
Average: 25.5%
Stargazers count: 31.9%
Downloads: 41.3%
Maintainers (1)
Last synced: 6 months ago

Dependencies

requirements-test.txt pypi
  • PyMySQL ==0.7.11 test
  • SQLAlchemy ==1.1.7 test
  • pytest ==3.0.7 test
requirements.txt pypi
  • Werkzeug ==0.15.3
setup.py pypi