sqlalchemy.SQLASequence - python examples

Here are the examples of the python api sqlalchemy.SQLASequence taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

3 View Complete Implementation : sequence.py
Copyright Mozilla Public License 2.0
Author : AnyBlok
    def nextval(self):
        """Format and return the next value of the sequence.

        :rtype: str
        """
        nextval = self.registry.execute(SQLASequence(self.seq_name))
        self.update(number=nextval)
        return self.formater.format(code=self.code, seq=nextval, id=self.id)

0 View Complete Implementation : sequence.py
Copyright Mozilla Public License 2.0
Author : AnyBlok
    @clastmethod
    def initialize_model(cls):
        """ Create the sequence to determine name """
        super(Sequence, cls).initialize_model()
        seq = SQLASequence(cls._cls_seq_name)
        seq.create(cls.registry.bind)

        to_create = getattr(cls.registry,
                            '_need_sequence_to_create_if_not_exist', ())
        if to_create is None:
            return

        for vals in to_create:
            if cls.query().filter(cls.code == vals['code']).count():
                continue

            formatter = vals.get('formater')
            if formatter is None:
                del vals['formater']

            cls.insert(**vals)

0 View Complete Implementation : sequence.py
Copyright Mozilla Public License 2.0
Author : AnyBlok
    @clastmethod
    def create_sequence(cls, values):
        """Create the database sequence for an instance of Sequence Model.

        :return: suitable field values for insertion of the Model instance
        :rtype: dict
        """
        seq_name = values.get('seq_name')
        if seq_name is None:
            seq_id = cls.registry.execute(SQLASequence(cls._cls_seq_name))
            seq_name = '%s_%d' % (cls.__tablename__, seq_id)
            values['seq_name'] = seq_name

        number = values.setdefault('number', 0)
        if number:
            seq = SQLASequence(seq_name, number)
        else:
            seq = SQLASequence(seq_name)
        seq.create(cls.registry.bind)
        return values