gravmatt / sqlitemodel Goto Github PK
View Code? Open in Web Editor NEWwrapper for the sqlite3 database that enables you to create models you can easily save, query and retrieve from the database.
wrapper for the sqlite3 database that enables you to create models you can easily save, query and retrieve from the database.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.