1.0.1 • Published 5 years ago

photon-ve v1.0.1

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

Simple TypeScript Script Example

This example shows how to use Photon JS in a simple TypeScript 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/typescript/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:

4. Seed the database data with this script

Execute the script with this command:

npm run seed

5. Run the script

Execute the script with this command:

npm run start

Next steps