Skip to content

Add deprecation warning for Python and Kotlin #1930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 9, 2022
Merged
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
11 changes: 11 additions & 0 deletions internal/config/v_two.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"fmt"
"io"
"os"
"path/filepath"

yaml "gopkg.in/yaml.v3"
Expand Down Expand Up @@ -83,6 +84,11 @@ func v2ParseConfig(rd io.Reader) (Config, error) {
}
}
if conf.SQL[j].Gen.Kotlin != nil {
fmt.Fprintf(os.Stderr, "WARNING: Built-in Kotlin support is deprecated.\n")
fmt.Fprintf(os.Stderr, " It will be removed in the next version (1.17.0).\n")
fmt.Fprintf(os.Stderr, " You will need to migrate to the sqlc-gen-kotlin plugin. See the step-by-step guide here:\n")
fmt.Fprintf(os.Stderr, " https://docs.sqlc.dev/en/latest/guides/migrating-to-sqlc-gen-kotlin.html\n")

if conf.SQL[j].Gen.Kotlin.Out == "" {
return conf, ErrNoOutPath
}
Expand All @@ -91,6 +97,11 @@ func v2ParseConfig(rd io.Reader) (Config, error) {
}
}
if conf.SQL[j].Gen.Python != nil {
fmt.Fprintf(os.Stderr, "WARNING: Built-in Python support is deprecated.\n")
fmt.Fprintf(os.Stderr, " It will be removed in the next version (1.17.0).\n")
fmt.Fprintf(os.Stderr, " You will need to migrate to the sqlc-gen-python plugin. See the step-by-step guide here:\n")
fmt.Fprintf(os.Stderr, " https://docs.sqlc.dev/en/latest/guides/migrating-to-sqlc-gen-python.html\n")

if conf.SQL[j].Gen.Python.QueryParameterLimit != nil {
if *conf.SQL[j].Gen.Python.QueryParameterLimit < 0 {
return conf, ErrInvalidQueryParameterLimit
Expand Down
4 changes: 4 additions & 0 deletions internal/endtoend/testdata/deprecated_kotlin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.gradle/
/.idea/
/build/
/out/
16 changes: 16 additions & 0 deletions internal/endtoend/testdata/deprecated_kotlin/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "2",
"sql": [
{
"schema": "src/main/resources/authors/postgresql/schema.sql",
"queries": "src/main/resources/authors/postgresql/query.sql",
"engine": "postgresql",
"gen": {
"kotlin": {
"out": "src/main/kotlin/com/example/authors/postgresql",
"package": "com.example.authors.postgresql"
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.15.0

package com.example.authors.postgresql

data class Author (
val id: Long,
val name: String,
val bio: String?
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.15.0

package com.example.authors.postgresql

import java.sql.Connection
import java.sql.SQLException
import java.sql.Statement

interface Queries {
@Throws(SQLException::class)
fun createAuthor(name: String, bio: String?): Author?

@Throws(SQLException::class)
fun deleteAuthor(id: Long)

@Throws(SQLException::class)
fun getAuthor(id: Long): Author?

@Throws(SQLException::class)
fun listAuthors(): List<Author>

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.15.0

package com.example.authors.postgresql

import java.sql.Connection
import java.sql.SQLException
import java.sql.Statement

const val createAuthor = """-- name: createAuthor :one
INSERT INTO authors (
name, bio
) VALUES (
?, ?
)
RETURNING id, name, bio
"""

const val deleteAuthor = """-- name: deleteAuthor :exec
DELETE FROM authors
WHERE id = ?
"""

const val getAuthor = """-- name: getAuthor :one
SELECT id, name, bio FROM authors
WHERE id = ? LIMIT 1
"""

const val listAuthors = """-- name: listAuthors :many
SELECT id, name, bio FROM authors
ORDER BY name
"""

class QueriesImpl(private val conn: Connection) : Queries {

@Throws(SQLException::class)
override fun createAuthor(name: String, bio: String?): Author? {
return conn.prepareStatement(createAuthor).use { stmt ->
stmt.setString(1, name)
stmt.setString(2, bio)

val results = stmt.executeQuery()
if (!results.next()) {
return null
}
val ret = Author(
results.getLong(1),
results.getString(2),
results.getString(3)
)
if (results.next()) {
throw SQLException("expected one row in result set, but got many")
}
ret
}
}

@Throws(SQLException::class)
override fun deleteAuthor(id: Long) {
conn.prepareStatement(deleteAuthor).use { stmt ->
stmt.setLong(1, id)

stmt.execute()
}
}

@Throws(SQLException::class)
override fun getAuthor(id: Long): Author? {
return conn.prepareStatement(getAuthor).use { stmt ->
stmt.setLong(1, id)

val results = stmt.executeQuery()
if (!results.next()) {
return null
}
val ret = Author(
results.getLong(1),
results.getString(2),
results.getString(3)
)
if (results.next()) {
throw SQLException("expected one row in result set, but got many")
}
ret
}
}

@Throws(SQLException::class)
override fun listAuthors(): List<Author> {
return conn.prepareStatement(listAuthors).use { stmt ->

val results = stmt.executeQuery()
val ret = mutableListOf<Author>()
while (results.next()) {
ret.add(Author(
results.getLong(1),
results.getString(2),
results.getString(3)
))
}
ret
}
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- name: GetAuthor :one
SELECT * FROM authors
WHERE id = $1 LIMIT 1;

-- name: ListAuthors :many
SELECT * FROM authors
ORDER BY name;

-- name: CreateAuthor :one
INSERT INTO authors (
name, bio
) VALUES (
$1, $2
)
RETURNING *;

-- name: DeleteAuthor :exec
DELETE FROM authors
WHERE id = $1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text
);
19 changes: 19 additions & 0 deletions internal/endtoend/testdata/deprecated_python/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- name: GetAuthor :one
SELECT * FROM authors
WHERE id = $1 LIMIT 1;

-- name: ListAuthors :many
SELECT * FROM authors
ORDER BY name;

-- name: CreateAuthor :one
INSERT INTO authors (
name, bio
) VALUES (
$1, $2
)
RETURNING *;

-- name: DeleteAuthor :exec
DELETE FROM authors
WHERE id = $1;
5 changes: 5 additions & 0 deletions internal/endtoend/testdata/deprecated_python/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text
);
18 changes: 18 additions & 0 deletions internal/endtoend/testdata/deprecated_python/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "2",
"sql": [
{
"schema": "schema.sql",
"queries": "query.sql",
"engine": "postgresql",
"gen": {
"python": {
"out": "src/authors",
"package": "authors",
"emit_sync_querier": true,
"emit_async_querier": true
}
}
}
]
}
12 changes: 12 additions & 0 deletions internal/endtoend/testdata/deprecated_python/src/authors/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Code generated by sqlc. DO NOT EDIT.
# versions:
# sqlc v1.15.0
import dataclasses
from typing import Optional


@dataclasses.dataclass()
class Author:
id: int
name: str
bio: Optional[str]
112 changes: 112 additions & 0 deletions internal/endtoend/testdata/deprecated_python/src/authors/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Code generated by sqlc. DO NOT EDIT.
# versions:
# sqlc v1.15.0
# source: query.sql
from typing import AsyncIterator, Iterator, Optional

import sqlalchemy
import sqlalchemy.ext.asyncio

from authors import models


CREATE_AUTHOR = """-- name: create_author \\:one
INSERT INTO authors (
name, bio
) VALUES (
:p1, :p2
)
RETURNING id, name, bio
"""


DELETE_AUTHOR = """-- name: delete_author \\:exec
DELETE FROM authors
WHERE id = :p1
"""


GET_AUTHOR = """-- name: get_author \\:one
SELECT id, name, bio FROM authors
WHERE id = :p1 LIMIT 1
"""


LIST_AUTHORS = """-- name: list_authors \\:many
SELECT id, name, bio FROM authors
ORDER BY name
"""


class Querier:
def __init__(self, conn: sqlalchemy.engine.Connection):
self._conn = conn

def create_author(self, *, name: str, bio: Optional[str]) -> Optional[models.Author]:
row = self._conn.execute(sqlalchemy.text(CREATE_AUTHOR), {"p1": name, "p2": bio}).first()
if row is None:
return None
return models.Author(
id=row[0],
name=row[1],
bio=row[2],
)

def delete_author(self, *, id: int) -> None:
self._conn.execute(sqlalchemy.text(DELETE_AUTHOR), {"p1": id})

def get_author(self, *, id: int) -> Optional[models.Author]:
row = self._conn.execute(sqlalchemy.text(GET_AUTHOR), {"p1": id}).first()
if row is None:
return None
return models.Author(
id=row[0],
name=row[1],
bio=row[2],
)

def list_authors(self) -> Iterator[models.Author]:
result = self._conn.execute(sqlalchemy.text(LIST_AUTHORS))
for row in result:
yield models.Author(
id=row[0],
name=row[1],
bio=row[2],
)


class AsyncQuerier:
def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
self._conn = conn

async def create_author(self, *, name: str, bio: Optional[str]) -> Optional[models.Author]:
row = (await self._conn.execute(sqlalchemy.text(CREATE_AUTHOR), {"p1": name, "p2": bio})).first()
if row is None:
return None
return models.Author(
id=row[0],
name=row[1],
bio=row[2],
)

async def delete_author(self, *, id: int) -> None:
await self._conn.execute(sqlalchemy.text(DELETE_AUTHOR), {"p1": id})

async def get_author(self, *, id: int) -> Optional[models.Author]:
row = (await self._conn.execute(sqlalchemy.text(GET_AUTHOR), {"p1": id})).first()
if row is None:
return None
return models.Author(
id=row[0],
name=row[1],
bio=row[2],
)

async def list_authors(self) -> AsyncIterator[models.Author]:
result = await self._conn.stream(sqlalchemy.text(LIST_AUTHORS))
async for row in result:
yield models.Author(
id=row[0],
name=row[1],
bio=row[2],
)