Skip to content

Commit 821e24a

Browse files
authored
Add deprecation warning for Python and Kotlin (#1930)
* chore: Add kotlin output * chore: Add python output * Add deprecation warnings
1 parent 05c1d25 commit 821e24a

File tree

13 files changed

+365
-0
lines changed

13 files changed

+365
-0
lines changed

internal/config/v_two.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
44
"fmt"
55
"io"
6+
"os"
67
"path/filepath"
78

89
yaml "gopkg.in/yaml.v3"
@@ -83,6 +84,11 @@ func v2ParseConfig(rd io.Reader) (Config, error) {
8384
}
8485
}
8586
if conf.SQL[j].Gen.Kotlin != nil {
87+
fmt.Fprintf(os.Stderr, "WARNING: Built-in Kotlin support is deprecated.\n")
88+
fmt.Fprintf(os.Stderr, " It will be removed in the next version (1.17.0).\n")
89+
fmt.Fprintf(os.Stderr, " You will need to migrate to the sqlc-gen-kotlin plugin. See the step-by-step guide here:\n")
90+
fmt.Fprintf(os.Stderr, " https://docs.sqlc.dev/en/latest/guides/migrating-to-sqlc-gen-kotlin.html\n")
91+
8692
if conf.SQL[j].Gen.Kotlin.Out == "" {
8793
return conf, ErrNoOutPath
8894
}
@@ -91,6 +97,11 @@ func v2ParseConfig(rd io.Reader) (Config, error) {
9197
}
9298
}
9399
if conf.SQL[j].Gen.Python != nil {
100+
fmt.Fprintf(os.Stderr, "WARNING: Built-in Python support is deprecated.\n")
101+
fmt.Fprintf(os.Stderr, " It will be removed in the next version (1.17.0).\n")
102+
fmt.Fprintf(os.Stderr, " You will need to migrate to the sqlc-gen-python plugin. See the step-by-step guide here:\n")
103+
fmt.Fprintf(os.Stderr, " https://docs.sqlc.dev/en/latest/guides/migrating-to-sqlc-gen-python.html\n")
104+
94105
if conf.SQL[j].Gen.Python.QueryParameterLimit != nil {
95106
if *conf.SQL[j].Gen.Python.QueryParameterLimit < 0 {
96107
return conf, ErrInvalidQueryParameterLimit
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.gradle/
2+
/.idea/
3+
/build/
4+
/out/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "2",
3+
"sql": [
4+
{
5+
"schema": "src/main/resources/authors/postgresql/schema.sql",
6+
"queries": "src/main/resources/authors/postgresql/query.sql",
7+
"engine": "postgresql",
8+
"gen": {
9+
"kotlin": {
10+
"out": "src/main/kotlin/com/example/authors/postgresql",
11+
"package": "com.example.authors.postgresql"
12+
}
13+
}
14+
}
15+
]
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Code generated by sqlc. DO NOT EDIT.
2+
// versions:
3+
// sqlc v1.15.0
4+
5+
package com.example.authors.postgresql
6+
7+
data class Author (
8+
val id: Long,
9+
val name: String,
10+
val bio: String?
11+
)
12+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Code generated by sqlc. DO NOT EDIT.
2+
// versions:
3+
// sqlc v1.15.0
4+
5+
package com.example.authors.postgresql
6+
7+
import java.sql.Connection
8+
import java.sql.SQLException
9+
import java.sql.Statement
10+
11+
interface Queries {
12+
@Throws(SQLException::class)
13+
fun createAuthor(name: String, bio: String?): Author?
14+
15+
@Throws(SQLException::class)
16+
fun deleteAuthor(id: Long)
17+
18+
@Throws(SQLException::class)
19+
fun getAuthor(id: Long): Author?
20+
21+
@Throws(SQLException::class)
22+
fun listAuthors(): List<Author>
23+
24+
}
25+
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Code generated by sqlc. DO NOT EDIT.
2+
// versions:
3+
// sqlc v1.15.0
4+
5+
package com.example.authors.postgresql
6+
7+
import java.sql.Connection
8+
import java.sql.SQLException
9+
import java.sql.Statement
10+
11+
const val createAuthor = """-- name: createAuthor :one
12+
INSERT INTO authors (
13+
name, bio
14+
) VALUES (
15+
?, ?
16+
)
17+
RETURNING id, name, bio
18+
"""
19+
20+
const val deleteAuthor = """-- name: deleteAuthor :exec
21+
DELETE FROM authors
22+
WHERE id = ?
23+
"""
24+
25+
const val getAuthor = """-- name: getAuthor :one
26+
SELECT id, name, bio FROM authors
27+
WHERE id = ? LIMIT 1
28+
"""
29+
30+
const val listAuthors = """-- name: listAuthors :many
31+
SELECT id, name, bio FROM authors
32+
ORDER BY name
33+
"""
34+
35+
class QueriesImpl(private val conn: Connection) : Queries {
36+
37+
@Throws(SQLException::class)
38+
override fun createAuthor(name: String, bio: String?): Author? {
39+
return conn.prepareStatement(createAuthor).use { stmt ->
40+
stmt.setString(1, name)
41+
stmt.setString(2, bio)
42+
43+
val results = stmt.executeQuery()
44+
if (!results.next()) {
45+
return null
46+
}
47+
val ret = Author(
48+
results.getLong(1),
49+
results.getString(2),
50+
results.getString(3)
51+
)
52+
if (results.next()) {
53+
throw SQLException("expected one row in result set, but got many")
54+
}
55+
ret
56+
}
57+
}
58+
59+
@Throws(SQLException::class)
60+
override fun deleteAuthor(id: Long) {
61+
conn.prepareStatement(deleteAuthor).use { stmt ->
62+
stmt.setLong(1, id)
63+
64+
stmt.execute()
65+
}
66+
}
67+
68+
@Throws(SQLException::class)
69+
override fun getAuthor(id: Long): Author? {
70+
return conn.prepareStatement(getAuthor).use { stmt ->
71+
stmt.setLong(1, id)
72+
73+
val results = stmt.executeQuery()
74+
if (!results.next()) {
75+
return null
76+
}
77+
val ret = Author(
78+
results.getLong(1),
79+
results.getString(2),
80+
results.getString(3)
81+
)
82+
if (results.next()) {
83+
throw SQLException("expected one row in result set, but got many")
84+
}
85+
ret
86+
}
87+
}
88+
89+
@Throws(SQLException::class)
90+
override fun listAuthors(): List<Author> {
91+
return conn.prepareStatement(listAuthors).use { stmt ->
92+
93+
val results = stmt.executeQuery()
94+
val ret = mutableListOf<Author>()
95+
while (results.next()) {
96+
ret.add(Author(
97+
results.getLong(1),
98+
results.getString(2),
99+
results.getString(3)
100+
))
101+
}
102+
ret
103+
}
104+
}
105+
106+
}
107+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- name: GetAuthor :one
2+
SELECT * FROM authors
3+
WHERE id = $1 LIMIT 1;
4+
5+
-- name: ListAuthors :many
6+
SELECT * FROM authors
7+
ORDER BY name;
8+
9+
-- name: CreateAuthor :one
10+
INSERT INTO authors (
11+
name, bio
12+
) VALUES (
13+
$1, $2
14+
)
15+
RETURNING *;
16+
17+
-- name: DeleteAuthor :exec
18+
DELETE FROM authors
19+
WHERE id = $1;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TABLE authors (
2+
id BIGSERIAL PRIMARY KEY,
3+
name text NOT NULL,
4+
bio text
5+
);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- name: GetAuthor :one
2+
SELECT * FROM authors
3+
WHERE id = $1 LIMIT 1;
4+
5+
-- name: ListAuthors :many
6+
SELECT * FROM authors
7+
ORDER BY name;
8+
9+
-- name: CreateAuthor :one
10+
INSERT INTO authors (
11+
name, bio
12+
) VALUES (
13+
$1, $2
14+
)
15+
RETURNING *;
16+
17+
-- name: DeleteAuthor :exec
18+
DELETE FROM authors
19+
WHERE id = $1;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TABLE authors (
2+
id BIGSERIAL PRIMARY KEY,
3+
name text NOT NULL,
4+
bio text
5+
);

0 commit comments

Comments
 (0)