Arangodb dump query12/27/2022 ![]() ![]() You will notice that the structure of the Post type is identical to our Post model that we defined earlier. For now, clients can only perform Query operations. This determines what type of operations clients can perform. Date ) def to_dict (self ) : return įirst of all, we have a schema type defined in the top. Integer, primary_key = True )Ĭreated_at = db. A Post will have a unique id, a title, description, and the date it was created.Ĭreate an api/models.py file and a new class called Post as shown below. In our database, we are going to have a Post table. Restart the server and make sure everything is working as usual. route ( '/' ) def hello ( ) : return 'My First API !!' config = "postgres://mycreds.db.:5432/ngimluxm"Īpp. We can now add this database url to the _ init_.py as shown below. If you’re using ElephantSQL, copy the DB URL as shown below, otherwise, copy the URL to where your SQL database is – whether it’s running locally on your machine or with another hosted SQL database service. In ElephantSQL, once the instance is provisioned on the cloud, we can see the database server information. I like ElephantSQL, a hosted SQL database, but you can use any SQL database you like. Adding a databaseįor this example, we are going to be using a Postgres DB instance. Before we enable it to use GraphQL, lets hook up a database and define some tables. Great! We can see our Flask app up and running. export FLASK_APP =app.pyįinally, we run the app by running the flask run command. In the command line, we can accomplish this by setting the FLASK_APP environment variable. Next, we tell Flask to start the application by looking at our app.py file. Let’s import the flask API instance using the following code: from api import app Our app.py file is what’s responsible for actually starting the flask app. The first file we’ll start working with is the api/_init_.py file, which will hold all the API-related configuration code.įor now, let’s populate the api/_init_.py with the following code. We will make the following directory structure. You can install them all using a single command: pip install flask ariadne flask-sqlalchemy flask-cors Up and running with a simple Flask app
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |