Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Latest commit

 

History

History
67 lines (43 loc) · 1.58 KB

File metadata and controls

67 lines (43 loc) · 1.58 KB

Simple Node Script Example

This example shows how to use Photon.js in a simple Node.js script to read and write data in a database.

How to use

1. Download example & install dependencies

Clone the repository:

git clone git@github.com:prisma/photonjs.git

Install Node dependencies:

cd photonjs/examples/javascript/script
npm install

2. Install the Prisma 2 CLI

To run the example, you need the Prisma 2 CLI:

npm install -g prisma2

3. Set up database

For this example, you'll use a simple SQLite database. To set up your database, run:

prisma2 lift save --name 'init'
prisma2 lift up

You can now use the SQLite Browser to view and edit your data in the ./prisma/dev.db file that was created when you ran prisma2 lift up.

4. Generate Photon (type-safe database client)

Run the following command to generate Photon.js:

prisma2 generate

Now you can seed your database using the seed script from package.json:

npm run seed

5. Run the script

Execute the script with this command:

npm run start

Next steps