Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ pgc.yaml
author.sql
schema.sql
queries/*
**/.DS_Store
tests/*/out_*
**/__pycache__
node_modules
4 changes: 2 additions & 2 deletions codegen/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pgc-codegen"
version = "0.1.0"
edition = "2018"
edition = "2024"

[profile.release]
lto = true
Expand Down
55 changes: 0 additions & 55 deletions codegen/foo.json

This file was deleted.

26 changes: 22 additions & 4 deletions codegen/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
use std::rc::Rc;
use std::sync::Arc;

use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("failed to deserialize request: {0}.\nThis may be a versioning issue between pgc and the codegen plugin being used.")]
#[error(
"failed to deserialize request: {0}.\nThis may be a versioning issue between pgc and the codegen plugin being used."
)]
RequestDeserialization(#[from] serde_json::Error),

#[error("language {0} is not supported.")]
NotSupportedLanguage(Rc<str>),
UnsupportedLanguage(Arc<str>),

#[error("failed to render or parse a template: {0}.\nThis is a bug in pgc, please report the issue at \"https://github.com/tvallotton/pgc\".")]
#[error("driver {driver} is not supported for {language}.")]
UnsupportedDriver {
driver: Arc<str>,
language: Arc<str>,
},

#[error(
"the language {language} requires the configuration option codegen.options.{option} to be present."
)]
MissingConfigurationOption {
language: &'static str,
option: &'static str,
},

#[error(
"failed to render or parse a template: {0}.\nThis is a bug in pgc, please report the issue at \"https://github.com/tvallotton/pgc\"."
)]
TemplateError(#[from] minijinja::Error),
}
45 changes: 45 additions & 0 deletions codegen/src/faker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use std::{collections::BTreeMap, sync::Arc};

use fake::{Dummy, Fake, Faker};

pub struct ArcFaker;
pub struct ArcStrFaker;
pub struct ValueFaker;

impl Dummy<ArcFaker> for Arc<str> {
fn dummy_with_rng<R: fake::Rng + ?Sized>(_: &ArcFaker, rng: &mut R) -> Self {
let str: String = Faker.fake_with_rng(rng);
Arc::from(str)
}
}

impl<T> Dummy<ArcFaker> for Arc<[T]>
where
Vec<T>: Dummy<Faker>,
{
fn dummy_with_rng<R: fake::Rng + ?Sized>(_: &ArcFaker, rng: &mut R) -> Self {
let str: Vec<T> = Faker.fake_with_rng(rng);
Arc::from(str)
}
}

impl Dummy<ArcStrFaker> for Arc<[Arc<str>]> {
fn dummy_with_rng<R: fake::Rng + ?Sized>(_: &ArcStrFaker, rng: &mut R) -> Self {
let str: Vec<String> = Faker.fake_with_rng(rng);
str.iter().map(|x| -> Arc<str> { (&**x).into() }).collect()
}
}

impl Dummy<ValueFaker> for serde_json::Value {
fn dummy_with_rng<R: fake::Rng + ?Sized>(_: &ValueFaker, rng: &mut R) -> Self {
serde_json::Value::Null
}
}

impl<V: Dummy<Faker>> Dummy<ArcFaker> for Arc<BTreeMap<Arc<str>, V>> {
fn dummy_with_rng<R: fake::Rng + ?Sized>(_: &ArcFaker, rng: &mut R) -> Self {
let map: BTreeMap<String, V> = Faker.fake_with_rng(rng);
let map = map.into_iter().map(|(k, v)| (Arc::from(&*k), v)).collect();
Arc::new(map)
}
}
21 changes: 0 additions & 21 deletions codegen/src/file_gen_config.rs

This file was deleted.

146 changes: 0 additions & 146 deletions codegen/src/file_generator.rs

This file was deleted.

Loading