Giter VIP home page Giter VIP logo

sqlitemodel's People

Contributors

gravmatt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sqlitemodel's Issues

Default Values not populated into Tables with Default Values.

I set up a table with this query:

CREATE TABLE "FCMembers" (
	"memberId"	TEXT NOT NULL UNIQUE,
	"name"	TEXT,
	"money"	INTEGER DEFAULT 1000,
	PRIMARY KEY("memberId")
);

Then I created a model with this code:

from sqlitemodel import Model, Database

CONFIG = "path/to/my/db"


class FCMember(Model):
    def __init__(self, memberId: str = "", dbfile=CONFIG):
        Database.DB_FILE = dbfile
        Model.__init__(self, memberId, dbfile=dbfile, foreign_keys=True)
        
        # The DiscordID of this member
        self.memberId = memberId
        # This is implicit from Model
        
        # The DiscordName of this member
        self.name = ""
        
        # The number of fox tokens this member has
        self.money = ""
        
        self.getModel()
        
    @staticmethod
    def tablename():
        return 'FCMembers'
    @staticmethod
    def columns():
        return [
            {
                "name":'memberId',
                "type":'TEXT',
            },
            {
                "name":'name',
                "type":'TEXT',
            },
            {
                "name":'money',
                "type":'INTEGER',
            },
        ]
fc_member = MyModel("1234")
fc_member.createTable()
fc_member.save()

print(fc_member.money) # outputs: ""

And the table had a new entry into it:
memberId name fox_tokens
1

When retrieving the money value, the default value was not applied to the model (which I can understand).

However, the table was given a new row with the correct ID in the ID field, a NULL name field, and a NULL money field. The default value was not populated into the field.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.