Skip to content

Commit

Permalink
chore(example): with sqlite (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
Seven Du authored Jun 5, 2024
1 parent dac8e6c commit ef21ec4
Show file tree
Hide file tree
Showing 10 changed files with 443 additions and 4 deletions.
7 changes: 7 additions & 0 deletions examples/with_sqlite/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="file:./dev.db"
7 changes: 7 additions & 0 deletions examples/with_sqlite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

lib/src/generated_prisma_client
prisma/dev.db
prisma-query-engine
30 changes: 30 additions & 0 deletions examples/with_sqlite/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
18 changes: 18 additions & 0 deletions examples/with_sqlite/bin/with_sqlite.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'dart:io';

import 'package:with_sqlite/with_sqlite.dart';

final datasourceUrl =
'file:${File.fromUri(Platform.script).parent.parent.path}/prisma/dev.db';
final prisma = PrismaClient(datasourceUrl: datasourceUrl);

Future<void> main() async {
try {
await prisma.$connect();

final games = await prisma.game.findMany();
print(games.map((e) => e.toJson()));
} finally {
await prisma.$disconnect();
}
}
Empty file added examples/with_sqlite/dev.db
Empty file.
3 changes: 3 additions & 0 deletions examples/with_sqlite/lib/with_sqlite.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'src/generated_prisma_client/client.dart';
export 'src/generated_prisma_client/model.dart';
export 'src/generated_prisma_client/prisma.dart';
19 changes: 19 additions & 0 deletions examples/with_sqlite/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "dart run orm"
output = "../lib/src/generated_prisma_client"
}

datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}

model Game {
id String @id @default(uuid()) @map("game_id")
name String @map("game_name")
@@map("games")
}
Loading

0 comments on commit ef21ec4

Please sign in to comment.