Skip to content

Instantly share code, notes, and snippets.

@cocuh
Created November 4, 2013 20:40
Show Gist options
  • Select an option

  • Save cocuh/7308872 to your computer and use it in GitHub Desktop.

Select an option

Save cocuh/7308872 to your computer and use it in GitHub Desktop.
minecraft recipe sql test
from sqlalchemy import (
create_engine,
Index,
Column,
ForeignKey,
Integer,
String,
Table,
)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import (
scoped_session,
sessionmaker,
relationship,
)
engine = create_engine('sqlite://')
session = scoped_session(sessionmaker())
session.configure(bind=engine)
Base = declarative_base()
before_association = Table('before_association', Base.metadata,
Column('item_id', Integer, ForeignKey('items.id')),
Column('recipe_id', Integer, ForeignKey('recipes.id')),
)
after_association = Table('after_association', Base.metadata,
Column('recipe_id', Integer, ForeignKey('recipes.id')),
Column('item_id', Integer, ForeignKey('items.id')),
)
class Item(Base):
__tablename__ = 'items'
id = Column(Integer, primary_key=True)
name = Column(String)
def __init__(self, name):
self.name = name
def __repr__(self):
return "<Item object name:%s>"%self.name
class Recipe(Base):
__tablename__ = 'recipes'
id = Column(Integer, primary_key=True)
outputs = relationship('Item', secondary=after_association, backref='out_recipes')
materials = relationship('Item', secondary=before_association, backref='in_recipes')
Base.metadata.create_all(engine)
cobblestone = Item('cobblestone')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment